diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-21 07:12:05 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-21 07:12:05 -0400 |
commit | 464b49eda26f6a518bda39a8d07e1d9b0f498897 (patch) | |
tree | 7d0c55221b3028c2843da88b41029abac864b4a5 | |
parent | Merge pull request #106 from FSMaxB/session-files (diff) | |
parent | Fixes to resizing and added in resize lock once boundaries are exceeded (diff) | |
download | sway-464b49eda26f6a518bda39a8d07e1d9b0f498897.tar.gz sway-464b49eda26f6a518bda39a8d07e1d9b0f498897.tar.zst sway-464b49eda26f6a518bda39a8d07e1d9b0f498897.zip |
Merge pull request #101 from Luminarys/master
Added in basic resizing command.
-rw-r--r-- | include/container.h | 4 | ||||
-rw-r--r-- | include/input_state.h | 4 | ||||
-rw-r--r-- | include/ipc.h | 12 | ||||
-rw-r--r-- | include/layout.h | 4 | ||||
-rw-r--r-- | sway/commands.c | 154 | ||||
-rw-r--r-- | sway/handlers.c | 134 | ||||
-rw-r--r-- | sway/input_state.c | 3 | ||||
-rw-r--r-- | sway/layout.c | 52 | ||||
-rw-r--r-- | sway/log.c | 5 | ||||
-rw-r--r-- | sway/type | 113 |
10 files changed, 453 insertions, 32 deletions
diff --git a/include/container.h b/include/container.h index fd621490..3598067c 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -33,12 +33,12 @@ struct sway_container { | |||
33 | enum swayc_layouts layout; | 33 | enum swayc_layouts layout; |
34 | 34 | ||
35 | // Not including borders or margins | 35 | // Not including borders or margins |
36 | int width, height; | 36 | double width, height; |
37 | 37 | ||
38 | // Used for setting floating geometry | 38 | // Used for setting floating geometry |
39 | int desired_width, desired_height; | 39 | int desired_width, desired_height; |
40 | 40 | ||
41 | int x, y; | 41 | double x, y; |
42 | 42 | ||
43 | bool visible; | 43 | bool visible; |
44 | bool is_floating; | 44 | bool is_floating; |
diff --git a/include/input_state.h b/include/input_state.h index a7e0c1ca..27dd6cff 100644 --- a/include/input_state.h +++ b/include/input_state.h | |||
@@ -34,6 +34,10 @@ extern struct pointer_state { | |||
34 | bool drag; | 34 | bool drag; |
35 | bool resize; | 35 | bool resize; |
36 | } floating; | 36 | } floating; |
37 | struct pointer_tiling { | ||
38 | bool resize; | ||
39 | swayc_t *init_view; | ||
40 | } tiling; | ||
37 | struct pointer_lock { | 41 | struct pointer_lock { |
38 | bool left; | 42 | bool left; |
39 | bool right; | 43 | bool right; |
diff --git a/include/ipc.h b/include/ipc.h index 0b6441f6..2d71c666 100644 --- a/include/ipc.h +++ b/include/ipc.h | |||
@@ -2,14 +2,14 @@ | |||
2 | #define _SWAY_IPC_H | 2 | #define _SWAY_IPC_H |
3 | 3 | ||
4 | enum ipc_command_type { | 4 | enum ipc_command_type { |
5 | IPC_COMMAND = 0, | 5 | IPC_COMMAND = 0, |
6 | IPC_GET_WORKSPACES = 1, | 6 | IPC_GET_WORKSPACES = 1, |
7 | IPC_SUBSCRIBE = 2, | 7 | IPC_SUBSCRIBE = 2, |
8 | IPC_GET_OUTPUTS = 3, | 8 | IPC_GET_OUTPUTS = 3, |
9 | IPC_GET_TREE = 4, | 9 | IPC_GET_TREE = 4, |
10 | IPC_GET_MARKS = 5, | 10 | IPC_GET_MARKS = 5, |
11 | IPC_GET_BAR_CONFIG = 6, | 11 | IPC_GET_BAR_CONFIG = 6, |
12 | IPC_GET_VERSION = 7, | 12 | IPC_GET_VERSION = 7, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | void ipc_init(void); | 15 | void ipc_init(void); |
diff --git a/include/layout.h b/include/layout.h index 75e72d2f..20044b95 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -18,7 +18,7 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child); | |||
18 | swayc_t *remove_child(swayc_t *child); | 18 | swayc_t *remove_child(swayc_t *child); |
19 | 19 | ||
20 | // Layout | 20 | // Layout |
21 | void arrange_windows(swayc_t *container, int width, int height); | 21 | void arrange_windows(swayc_t *container, double width, double height); |
22 | 22 | ||
23 | // Focus | 23 | // Focus |
24 | void unfocus_all(swayc_t *container); | 24 | void unfocus_all(swayc_t *container); |
@@ -29,4 +29,6 @@ swayc_t *get_focused_container(swayc_t *parent); | |||
29 | swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); | 29 | swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); |
30 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); | 30 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); |
31 | 31 | ||
32 | void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge); | ||
33 | |||
32 | #endif | 34 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index 3ac7f4dd..d1bbdc89 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -421,6 +421,159 @@ static bool cmd_reload(struct sway_config *config, int argc, char **argv) { | |||
421 | return true; | 421 | return true; |
422 | } | 422 | } |
423 | 423 | ||
424 | static bool cmd_resize(struct sway_config *config, int argc, char **argv) { | ||
425 | if (!checkarg(argc, "resize", EXPECTED_AT_LEAST, 3)) { | ||
426 | return false; | ||
427 | } | ||
428 | char *end; | ||
429 | int amount = (int)strtol(argv[2], &end, 10); | ||
430 | if (errno == ERANGE || amount == 0) { | ||
431 | errno = 0; | ||
432 | return false; | ||
433 | } | ||
434 | if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) { | ||
435 | return false; | ||
436 | } | ||
437 | if (strcmp(argv[0], "shrink") == 0) { | ||
438 | amount *= -1; | ||
439 | } | ||
440 | |||
441 | swayc_t *parent = get_focused_view(active_workspace); | ||
442 | swayc_t *focused = parent; | ||
443 | swayc_t *sibling; | ||
444 | if (!parent) { | ||
445 | return true; | ||
446 | } | ||
447 | // Find the closest parent container which has siblings of the proper layout. | ||
448 | // Then apply the resize to all of them. | ||
449 | int i; | ||
450 | if (strcmp(argv[1], "width") == 0) { | ||
451 | int lnumber = 0; | ||
452 | int rnumber = 0; | ||
453 | while (parent->parent) { | ||
454 | if (parent->parent->layout == L_HORIZ) { | ||
455 | for (i = 0; i < parent->parent->children->length; i++) { | ||
456 | sibling = parent->parent->children->items[i]; | ||
457 | if (sibling->x != focused->x) { | ||
458 | if (sibling->x < parent->x) { | ||
459 | lnumber++; | ||
460 | } else if (sibling->x > parent->x) { | ||
461 | rnumber++; | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | if (rnumber || lnumber) { | ||
466 | break; | ||
467 | } | ||
468 | } | ||
469 | parent = parent->parent; | ||
470 | } | ||
471 | if (parent == &root_container) { | ||
472 | return true; | ||
473 | } | ||
474 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); | ||
475 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
476 | for (i = 0; i < parent->parent->children->length; i++) { | ||
477 | sibling = parent->parent->children->items[i]; | ||
478 | if (sibling->x != focused->x) { | ||
479 | if (sibling->x < parent->x) { | ||
480 | double pixels = -1 * amount; | ||
481 | pixels /= lnumber; | ||
482 | if (rnumber) { | ||
483 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT); | ||
484 | } else { | ||
485 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT); | ||
486 | } | ||
487 | } else if (sibling->x > parent->x) { | ||
488 | double pixels = -1 * amount; | ||
489 | pixels /= rnumber; | ||
490 | if (lnumber) { | ||
491 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT); | ||
492 | } else { | ||
493 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT); | ||
494 | } | ||
495 | } | ||
496 | } else { | ||
497 | if (rnumber != 0 && lnumber != 0) { | ||
498 | double pixels = amount; | ||
499 | pixels /= 2; | ||
500 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT); | ||
501 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT); | ||
502 | } else if (rnumber) { | ||
503 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT); | ||
504 | } else if (lnumber) { | ||
505 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT); | ||
506 | } | ||
507 | } | ||
508 | } | ||
509 | // Recursive resize does not handle positions, let arrange_windows | ||
510 | // take care of that. | ||
511 | arrange_windows(active_workspace, -1, -1); | ||
512 | return true; | ||
513 | } else if (strcmp(argv[1], "height") == 0) { | ||
514 | int tnumber = 0; | ||
515 | int bnumber = 0; | ||
516 | while (parent->parent) { | ||
517 | if (parent->parent->layout == L_VERT) { | ||
518 | for (i = 0; i < parent->parent->children->length; i++) { | ||
519 | sibling = parent->parent->children->items[i]; | ||
520 | if (sibling->y != focused->y) { | ||
521 | if (sibling->y < parent->y) { | ||
522 | bnumber++; | ||
523 | } else if (sibling->y > parent->y) { | ||
524 | tnumber++; | ||
525 | } | ||
526 | } | ||
527 | } | ||
528 | if (bnumber || tnumber) { | ||
529 | break; | ||
530 | } | ||
531 | } | ||
532 | parent = parent->parent; | ||
533 | } | ||
534 | if (parent == &root_container) { | ||
535 | return true; | ||
536 | } | ||
537 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); | ||
538 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
539 | for (i = 0; i < parent->parent->children->length; i++) { | ||
540 | sibling = parent->parent->children->items[i]; | ||
541 | if (sibling->y != focused->y) { | ||
542 | if (sibling->y < parent->y) { | ||
543 | double pixels = -1 * amount; | ||
544 | pixels /= bnumber; | ||
545 | if (tnumber) { | ||
546 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM); | ||
547 | } else { | ||
548 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM); | ||
549 | } | ||
550 | } else if (sibling->x > parent->x) { | ||
551 | double pixels = -1 * amount; | ||
552 | pixels /= tnumber; | ||
553 | if (bnumber) { | ||
554 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP); | ||
555 | } else { | ||
556 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP); | ||
557 | } | ||
558 | } | ||
559 | } else { | ||
560 | if (bnumber != 0 && tnumber != 0) { | ||
561 | double pixels = amount/2; | ||
562 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP); | ||
563 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM); | ||
564 | } else if (tnumber) { | ||
565 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP); | ||
566 | } else if (bnumber) { | ||
567 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM); | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | arrange_windows(active_workspace, -1, -1); | ||
572 | return true; | ||
573 | } | ||
574 | return true; | ||
575 | } | ||
576 | |||
424 | static bool cmd_set(struct sway_config *config, int argc, char **argv) { | 577 | static bool cmd_set(struct sway_config *config, int argc, char **argv) { |
425 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { | 578 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { |
426 | return false; | 579 | return false; |
@@ -584,6 +737,7 @@ static struct cmd_handler handlers[] = { | |||
584 | { "layout", cmd_layout }, | 737 | { "layout", cmd_layout }, |
585 | { "log_colors", cmd_log_colors }, | 738 | { "log_colors", cmd_log_colors }, |
586 | { "reload", cmd_reload }, | 739 | { "reload", cmd_reload }, |
740 | { "resize", cmd_resize }, | ||
587 | { "set", cmd_set }, | 741 | { "set", cmd_set }, |
588 | { "split", cmd_split }, | 742 | { "split", cmd_split }, |
589 | { "splith", cmd_splith }, | 743 | { "splith", cmd_splith }, |
diff --git a/sway/handlers.c b/sway/handlers.c index 79628fe5..53eae439 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <xkbcommon/xkbcommon.h> | 1 | #include <xkbcommon/xkbcommon.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <math.h> | ||
4 | #include <wlc/wlc.h> | 5 | #include <wlc/wlc.h> |
5 | #include <ctype.h> | 6 | #include <ctype.h> |
6 | 7 | ||
@@ -338,11 +339,14 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
338 | static wlc_handle prev_handle = 0; | 339 | static wlc_handle prev_handle = 0; |
339 | mouse_origin = *origin; | 340 | mouse_origin = *origin; |
340 | bool changed_floating = false; | 341 | bool changed_floating = false; |
342 | bool changed_tiling = false; | ||
343 | int min_sane_w = 100; | ||
344 | int min_sane_h = 60; | ||
341 | if (!active_workspace) { | 345 | if (!active_workspace) { |
342 | return false; | 346 | return false; |
343 | } | 347 | } |
344 | // Do checks to determine if proper keys are being held | 348 | // Do checks to determine if proper keys are being held |
345 | swayc_t *view = get_focused_view(active_workspace); | 349 | swayc_t *view = container_under_pointer(); |
346 | uint32_t edge = 0; | 350 | uint32_t edge = 0; |
347 | if (pointer_state.floating.drag && view) { | 351 | if (pointer_state.floating.drag && view) { |
348 | if (view->is_floating) { | 352 | if (view->is_floating) { |
@@ -356,8 +360,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
356 | if (view->is_floating) { | 360 | if (view->is_floating) { |
357 | int dx = mouse_origin.x - prev_pos.x; | 361 | int dx = mouse_origin.x - prev_pos.x; |
358 | int dy = mouse_origin.y - prev_pos.y; | 362 | int dy = mouse_origin.y - prev_pos.y; |
359 | int min_sane_w = 100; | ||
360 | int min_sane_h = 60; | ||
361 | 363 | ||
362 | // Move and resize the view based on the dx/dy and mouse position | 364 | // Move and resize the view based on the dx/dy and mouse position |
363 | int midway_x = view->x + view->width/2; | 365 | int midway_x = view->x + view->width/2; |
@@ -417,6 +419,106 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
417 | } | 419 | } |
418 | } | 420 | } |
419 | } | 421 | } |
422 | } | ||
423 | } else if (pointer_state.tiling.resize && view) { | ||
424 | if (view != pointer_state.tiling.init_view) { | ||
425 | // Quit out of the resize | ||
426 | pointer_state.tiling.init_view = NULL; | ||
427 | } | ||
428 | if (!view->is_floating && view == pointer_state.tiling.init_view) { | ||
429 | // Handle layout resizes -- Find the biggest parent container then apply resizes to that | ||
430 | // and its bordering siblings | ||
431 | swayc_t *parent = view; | ||
432 | double dx = mouse_origin.x - prev_pos.x; | ||
433 | double dy = mouse_origin.y - prev_pos.y; | ||
434 | if (pointer_state.lock.top) { | ||
435 | while (parent->type != C_WORKSPACE) { | ||
436 | // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better | ||
437 | // way of doing this. | ||
438 | if (fabs(parent->parent->y + parent->parent->height - (view->y + view->height)) <= 1) { | ||
439 | parent = parent->parent; | ||
440 | } else { | ||
441 | break; | ||
442 | } | ||
443 | } | ||
444 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { | ||
445 | sway_log(L_DEBUG, "Top is locked, found biggest valid parent at: %p", parent); | ||
446 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); | ||
447 | if (sibling) { | ||
448 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
449 | if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { | ||
450 | recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); | ||
451 | recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); | ||
452 | changed_tiling = true; | ||
453 | } | ||
454 | } | ||
455 | } | ||
456 | } else { | ||
457 | while (parent->type != C_WORKSPACE) { | ||
458 | if (fabs(parent->parent->y - view->y) <= 1) { | ||
459 | parent = parent->parent; | ||
460 | } else { | ||
461 | break; | ||
462 | } | ||
463 | } | ||
464 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { | ||
465 | sway_log(L_DEBUG, "Bot is locked, found biggest valid parent at: %p", parent); | ||
466 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); | ||
467 | if (sibling) { | ||
468 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
469 | if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { | ||
470 | recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); | ||
471 | recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); | ||
472 | changed_tiling = true; | ||
473 | } | ||
474 | } | ||
475 | } | ||
476 | } | ||
477 | |||
478 | parent = view; | ||
479 | if (pointer_state.lock.left) { | ||
480 | while (parent->type != C_WORKSPACE) { | ||
481 | if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) { | ||
482 | parent = parent->parent; | ||
483 | } else { | ||
484 | sway_log(L_DEBUG, "view: %f vs parent: %f", view->x + view->width, parent->parent->x + parent->parent->width); | ||
485 | break; | ||
486 | } | ||
487 | } | ||
488 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { | ||
489 | sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent); | ||
490 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); | ||
491 | if (sibling) { | ||
492 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
493 | if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { | ||
494 | recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); | ||
495 | recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); | ||
496 | changed_tiling = true; | ||
497 | } | ||
498 | } | ||
499 | } | ||
500 | } else { | ||
501 | while (parent->type != C_WORKSPACE) { | ||
502 | if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) { | ||
503 | parent = parent->parent; | ||
504 | } else { | ||
505 | break; | ||
506 | } | ||
507 | } | ||
508 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { | ||
509 | sway_log(L_DEBUG, "Right is locked, found biggest valid parent at: %p", parent); | ||
510 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); | ||
511 | if (sibling) { | ||
512 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
513 | if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { | ||
514 | recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); | ||
515 | recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); | ||
516 | changed_tiling = true; | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | } | ||
521 | arrange_windows(active_workspace, -1, -1); | ||
420 | } | 522 | } |
421 | } | 523 | } |
422 | if (config->focus_follows_mouse && prev_handle != handle) { | 524 | if (config->focus_follows_mouse && prev_handle != handle) { |
@@ -443,6 +545,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
443 | wlc_view_set_geometry(view->handle, edge, &geometry); | 545 | wlc_view_set_geometry(view->handle, edge, &geometry); |
444 | return true; | 546 | return true; |
445 | } | 547 | } |
548 | if (changed_tiling) { | ||
549 | return true; | ||
550 | } | ||
446 | return false; | 551 | return false; |
447 | } | 552 | } |
448 | 553 | ||
@@ -463,7 +568,16 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
463 | pointer_state.r_held = true; | 568 | pointer_state.r_held = true; |
464 | } | 569 | } |
465 | swayc_t *pointer = container_under_pointer(); | 570 | swayc_t *pointer = container_under_pointer(); |
466 | set_focused_container(pointer); | 571 | if (pointer) { |
572 | set_focused_container(pointer); | ||
573 | int midway_x = pointer->x + pointer->width/2; | ||
574 | int midway_y = pointer->y + pointer->height/2; | ||
575 | pointer_state.lock.bottom = origin->y < midway_y; | ||
576 | pointer_state.lock.top = !pointer_state.lock.bottom; | ||
577 | pointer_state.lock.right = origin->x < midway_x; | ||
578 | pointer_state.lock.left = !pointer_state.lock.right; | ||
579 | } | ||
580 | |||
467 | if (pointer->is_floating) { | 581 | if (pointer->is_floating) { |
468 | int i; | 582 | int i; |
469 | for (i = 0; i < pointer->parent->floating->length; i++) { | 583 | for (i = 0; i < pointer->parent->floating->length; i++) { |
@@ -475,19 +589,15 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
475 | } | 589 | } |
476 | arrange_windows(pointer->parent, -1, -1); | 590 | arrange_windows(pointer->parent, -1, -1); |
477 | if (modifiers->mods & config->floating_mod) { | 591 | if (modifiers->mods & config->floating_mod) { |
478 | int midway_x = pointer->x + pointer->width/2; | ||
479 | int midway_y = pointer->y + pointer->height/2; | ||
480 | |||
481 | pointer_state.floating.drag = pointer_state.l_held; | 592 | pointer_state.floating.drag = pointer_state.l_held; |
482 | pointer_state.floating.resize = pointer_state.r_held; | 593 | pointer_state.floating.resize = pointer_state.r_held; |
483 | pointer_state.lock.bottom = origin->y < midway_y; | ||
484 | pointer_state.lock.top = !pointer_state.lock.bottom; | ||
485 | pointer_state.lock.right = origin->x < midway_x; | ||
486 | pointer_state.lock.left = !pointer_state.lock.right; | ||
487 | start_floating(pointer); | 594 | start_floating(pointer); |
488 | } | 595 | } |
489 | // Dont want pointer sent to window while dragging or resizing | 596 | // Dont want pointer sent to window while dragging or resizing |
490 | return (pointer_state.floating.drag || pointer_state.floating.resize); | 597 | return (pointer_state.floating.drag || pointer_state.floating.resize); |
598 | } else { | ||
599 | pointer_state.tiling.resize = pointer_state.r_held; | ||
600 | pointer_state.tiling.init_view = pointer; | ||
491 | } | 601 | } |
492 | return (pointer && pointer != focused); | 602 | return (pointer && pointer != focused); |
493 | } else { | 603 | } else { |
@@ -499,6 +609,8 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
499 | if (button == M_RIGHT_CLICK) { | 609 | if (button == M_RIGHT_CLICK) { |
500 | pointer_state.r_held = false; | 610 | pointer_state.r_held = false; |
501 | pointer_state.floating.resize = false; | 611 | pointer_state.floating.resize = false; |
612 | pointer_state.tiling.resize = false; | ||
613 | pointer_state.tiling.init_view = NULL; | ||
502 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; | 614 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; |
503 | } | 615 | } |
504 | } | 616 | } |
diff --git a/sway/input_state.c b/sway/input_state.c index 7f312c54..ef5d6df0 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -48,7 +48,7 @@ void release_key(keycode key) { | |||
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0, 0}}; | 51 | struct pointer_state pointer_state = {0, 0, {0, 0}, {0}, {0, 0, 0, 0}}; |
52 | 52 | ||
53 | static struct wlc_geometry saved_floating; | 53 | static struct wlc_geometry saved_floating; |
54 | 54 | ||
@@ -72,4 +72,3 @@ void reset_floating(swayc_t *view) { | |||
72 | pointer_state.floating = (struct pointer_floating){0,0}; | 72 | pointer_state.floating = (struct pointer_floating){0,0}; |
73 | pointer_state.lock = (struct pointer_lock){0,0,0,0}; | 73 | pointer_state.lock = (struct pointer_lock){0,0,0,0}; |
74 | } | 74 | } |
75 | |||
diff --git a/sway/layout.c b/sway/layout.c index 8c011fdb..35aa4942 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -29,7 +29,7 @@ static int index_child(swayc_t *parent, swayc_t *child) { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | void add_child(swayc_t *parent, swayc_t *child) { | 31 | void add_child(swayc_t *parent, swayc_t *child) { |
32 | sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, | 32 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, |
33 | child->width, child->height, parent, parent->type, parent->width, parent->height); | 33 | child->width, child->height, parent, parent->type, parent->width, parent->height); |
34 | list_add(parent->children, child); | 34 | list_add(parent->children, child); |
35 | child->parent = parent; | 35 | child->parent = parent; |
@@ -40,7 +40,7 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | void add_floating(swayc_t *ws, swayc_t *child) { | 42 | void add_floating(swayc_t *ws, swayc_t *child) { |
43 | sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, | 43 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, |
44 | child->width, child->height, ws, ws->type, ws->width, ws->height); | 44 | child->width, child->height, ws, ws->type, ws->width, ws->height); |
45 | list_add(ws->floating, child); | 45 | list_add(ws->floating, child); |
46 | child->parent = ws; | 46 | child->parent = ws; |
@@ -109,7 +109,7 @@ swayc_t *remove_child(swayc_t *child) { | |||
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | void arrange_windows(swayc_t *container, int width, int height) { | 112 | void arrange_windows(swayc_t *container, double width, double height) { |
113 | int i; | 113 | int i; |
114 | if (width == -1 || height == -1) { | 114 | if (width == -1 || height == -1) { |
115 | sway_log(L_DEBUG, "Arranging layout for %p", container); | 115 | sway_log(L_DEBUG, "Arranging layout for %p", container); |
@@ -144,7 +144,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
144 | child->y = y + container->gaps; | 144 | child->y = y + container->gaps; |
145 | child->width = width - container->gaps * 2; | 145 | child->width = width - container->gaps * 2; |
146 | child->height = height - container->gaps * 2; | 146 | child->height = height - container->gaps * 2; |
147 | sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y); | 147 | sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); |
148 | arrange_windows(child, -1, -1); | 148 | arrange_windows(child, -1, -1); |
149 | } | 149 | } |
150 | return; | 150 | return; |
@@ -190,7 +190,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
190 | default: | 190 | default: |
191 | // Calculate total width | 191 | // Calculate total width |
192 | for (i = 0; i < container->children->length; ++i) { | 192 | for (i = 0; i < container->children->length; ++i) { |
193 | int *old_width = &((swayc_t *)container->children->items[i])->width; | 193 | double *old_width = &((swayc_t *)container->children->items[i])->width; |
194 | if (*old_width <= 0) { | 194 | if (*old_width <= 0) { |
195 | if (container->children->length > 1) { | 195 | if (container->children->length > 1) { |
196 | *old_width = width / (container->children->length - 1); | 196 | *old_width = width / (container->children->length - 1); |
@@ -206,7 +206,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
206 | sway_log(L_DEBUG, "Arranging %p horizontally", container); | 206 | sway_log(L_DEBUG, "Arranging %p horizontally", container); |
207 | for (i = 0; i < container->children->length; ++i) { | 207 | for (i = 0; i < container->children->length; ++i) { |
208 | swayc_t *child = container->children->items[i]; | 208 | swayc_t *child = container->children->items[i]; |
209 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale); | 209 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); |
210 | child->x = x + container->x; | 210 | child->x = x + container->x; |
211 | child->y = y + container->y; | 211 | child->y = y + container->y; |
212 | arrange_windows(child, child->width * scale, height); | 212 | arrange_windows(child, child->width * scale, height); |
@@ -217,7 +217,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
217 | case L_VERT: | 217 | case L_VERT: |
218 | // Calculate total height | 218 | // Calculate total height |
219 | for (i = 0; i < container->children->length; ++i) { | 219 | for (i = 0; i < container->children->length; ++i) { |
220 | int *old_height = &((swayc_t *)container->children->items[i])->height; | 220 | double *old_height = &((swayc_t *)container->children->items[i])->height; |
221 | if (*old_height <= 0) { | 221 | if (*old_height <= 0) { |
222 | if (container->children->length > 1) { | 222 | if (container->children->length > 1) { |
223 | *old_height = height / (container->children->length - 1); | 223 | *old_height = height / (container->children->length - 1); |
@@ -233,7 +233,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
233 | sway_log(L_DEBUG, "Arranging %p vertically", container); | 233 | sway_log(L_DEBUG, "Arranging %p vertically", container); |
234 | for (i = 0; i < container->children->length; ++i) { | 234 | for (i = 0; i < container->children->length; ++i) { |
235 | swayc_t *child = container->children->items[i]; | 235 | swayc_t *child = container->children->items[i]; |
236 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale); | 236 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); |
237 | child->x = x + container->x; | 237 | child->x = x + container->x; |
238 | child->y = y + container->y; | 238 | child->y = y + container->y; |
239 | arrange_windows(child, width, child->height * scale); | 239 | arrange_windows(child, width, child->height * scale); |
@@ -364,3 +364,39 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) | |||
364 | } | 364 | } |
365 | } | 365 | } |
366 | } | 366 | } |
367 | |||
368 | void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) { | ||
369 | int i; | ||
370 | bool layout_match = true; | ||
371 | sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); | ||
372 | if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) { | ||
373 | container->width += amount; | ||
374 | layout_match = container->layout == L_HORIZ; | ||
375 | } else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) { | ||
376 | container->height += amount; | ||
377 | layout_match = container->layout == L_VERT; | ||
378 | } | ||
379 | if (container->type == C_VIEW) { | ||
380 | struct wlc_geometry geometry = { | ||
381 | .origin = { | ||
382 | .x = container->x + container->gaps / 2, | ||
383 | .y = container->y + container->gaps / 2 | ||
384 | }, | ||
385 | .size = { | ||
386 | .w = container->width - container->gaps, | ||
387 | .h = container->height - container->gaps | ||
388 | } | ||
389 | }; | ||
390 | wlc_view_set_geometry(container->handle, edge, &geometry); | ||
391 | return; | ||
392 | } | ||
393 | if (layout_match) { | ||
394 | for (i = 0; i < container->children->length; i++) { | ||
395 | recursive_resize(container->children->items[i], amount/container->children->length, edge); | ||
396 | } | ||
397 | } else { | ||
398 | for (i = 0; i < container->children->length; i++) { | ||
399 | recursive_resize(container->children->items[i], amount, edge); | ||
400 | } | ||
401 | } | ||
402 | } | ||
@@ -142,13 +142,14 @@ static void container_log(const swayc_t *c) { | |||
142 | c->layout == L_STACKED ? "Stacked|": | 142 | c->layout == L_STACKED ? "Stacked|": |
143 | c->layout == L_FLOATING ? "Floating|": | 143 | c->layout == L_FLOATING ? "Floating|": |
144 | "Unknown|"); | 144 | "Unknown|"); |
145 | fprintf(stderr, "w:%d|h:%d|", c->width, c->height); | 145 | fprintf(stderr, "w:%f|h:%f|", c->width, c->height); |
146 | fprintf(stderr, "x:%d|y:%d|", c->x, c->y); | 146 | fprintf(stderr, "x:%f|y:%f|", c->x, c->y); |
147 | fprintf(stderr, "vis:%c|", c->visible?'t':'f'); | 147 | fprintf(stderr, "vis:%c|", c->visible?'t':'f'); |
148 | fprintf(stderr, "name:%.16s|", c->name); | 148 | fprintf(stderr, "name:%.16s|", c->name); |
149 | fprintf(stderr, "children:%d\n",c->children?c->children->length:0); | 149 | fprintf(stderr, "children:%d\n",c->children?c->children->length:0); |
150 | } | 150 | } |
151 | void layout_log(const swayc_t *c, int depth) { | 151 | void layout_log(const swayc_t *c, int depth) { |
152 | if (L_DEBUG > v) return; | ||
152 | int i, d; | 153 | int i, d; |
153 | int e = c->children ? c->children->length : 0; | 154 | int e = c->children ? c->children->length : 0; |
154 | container_log(c); | 155 | container_log(c); |
diff --git a/sway/type b/sway/type new file mode 100644 index 00000000..c7bebe5e --- /dev/null +++ b/sway/type | |||
@@ -0,0 +1,113 @@ | |||
1 | workspace.c:78:9: while (parent->type != C_OUTPUT) { | ||
2 | workspace.c:79:12: parent = parent->parent; | ||
3 | |||
4 | focus.c:16:6: if (parent->focused != c) { | ||
5 | focus.c:30:8: if (parent->focused) { | ||
6 | focus.c:31:19: swayc_t *ws = parent->focused; | ||
7 | focus.c:38:25: wlc_output_set_mask(parent->handle, 2); | ||
8 | focus.c:39:8: c->parent->focused = c; | ||
9 | focus.c:53:5: c->parent->focused = c; | ||
10 | focus.c:71:20: while (parent && !parent->is_focused) { | ||
11 | focus.c:72:12: parent = parent->focused; | ||
12 | focus.c:143:13: if (find->parent->focused != find) { | ||
13 | focus.c:167:19: while (parent && parent->type != C_VIEW) { | ||
14 | focus.c:168:7: if (parent->type == C_WORKSPACE && parent->focused == NULL) { | ||
15 | focus.c:171:12: parent = parent->focused; | ||
16 | |||
17 | handlers.c:24:9: while (parent->type != C_OUTPUT) { | ||
18 | handlers.c:25:12: parent = parent->parent; | ||
19 | handlers.c:436:18: while (parent->parent && parent->y + parent->height == view->y + view->height && parent->type != L_WORKSPACE) { | ||
20 | handlers.c:437:30: parent = parent->parent; | ||
21 | handlers.c:440:50: if (parent == &root_container || parent->children->length == 1) { | ||
22 | handlers.c:444:18: while (parent->parent && parent->y == view->y) { | ||
23 | handlers.c:445:30: parent = parent->parent; | ||
24 | handlers.c:448:50: if (parent == &root_container || parent->children->length == 1) { | ||
25 | handlers.c:454:18: while (parent->parent && parent->x + parent->width == view->x + view->width) { | ||
26 | handlers.c:455:30: parent = parent->parent; | ||
27 | handlers.c:458:50: if (parent == &root_container || parent->children->length == 1) { | ||
28 | handlers.c:462:18: while (parent->parent && parent->x + parent->width == view->x) { | ||
29 | handlers.c:463:30: parent = parent->parent; | ||
30 | handlers.c:466:50: if (parent == &root_container || parent->children->length == 1) { | ||
31 | handlers.c:528:29: for (i = 0; i < pointer->parent->floating->length; i++) { | ||
32 | handlers.c:529:18: if (pointer->parent->floating->items[i] == pointer) { | ||
33 | handlers.c:530:24: list_del(pointer->parent->floating, i); | ||
34 | handlers.c:531:24: list_add(pointer->parent->floating, pointer); | ||
35 | |||
36 | container.c:284:6: if (parent->type == C_CONTAINER) { | ||
37 | |||
38 | layout.c:23:18: for (i = 0; i < parent->children->length; ++i) { | ||
39 | layout.c:24:7: if (parent->children->items[i] == child) { | ||
40 | layout.c:33:40: child->width, child->height, parent, parent->type, parent->width, parent->height); | ||
41 | layout.c:34:11: list_add(parent->children, child); | ||
42 | layout.c:37:6: if (parent->children->length == 1) { | ||
43 | layout.c:56:11: if (i == parent->children->length) { | ||
44 | layout.c:59:14: list_insert(parent->children, i+1, child); | ||
45 | layout.c:70:2: parent->children->items[i] = new_child; | ||
46 | layout.c:73:13: if (child->parent->focused == child) { | ||
47 | layout.c:85:19: for (i = 0; i < parent->floating->length; ++i) { | ||
48 | layout.c:86:8: if (parent->floating->items[i] == child) { | ||
49 | layout.c:87:14: list_del(parent->floating, i); | ||
50 | layout.c:93:19: for (i = 0; i < parent->children->length; ++i) { | ||
51 | layout.c:94:8: if (parent->children->items[i] == child) { | ||
52 | layout.c:95:14: list_del(parent->children, i); | ||
53 | layout.c:101:6: if (parent->focused == child) { | ||
54 | layout.c:102:7: if (parent->children->length > 0) { | ||
55 | layout.c:103:38: set_focused_container_for(parent, parent->children->items[i?i-1:0]); | ||
56 | layout.c:105:4: parent->focused = NULL; | ||
57 | layout.c:165:12: while (parent->type != C_OUTPUT) { | ||
58 | layout.c:166:15: parent = parent->parent; | ||
59 | layout.c:170:23: geometry.size.w = parent->width; | ||
60 | layout.c:171:23: geometry.size.h = parent->height; | ||
61 | layout.c:267:13: while (parent->type != C_OUTPUT) { | ||
62 | layout.c:268:16: parent = parent->parent; | ||
63 | layout.c:272:24: geometry.size.w = parent->width; | ||
64 | layout.c:273:24: geometry.size.h = parent->height; | ||
65 | layout.c:294:6: if (parent->children == NULL) { | ||
66 | layout.c:300:6: if (parent->type == C_WORKSPACE) { | ||
67 | layout.c:301:19: for (i = 0; i < parent->floating->length; ++i) { | ||
68 | layout.c:302:21: swayc_t *child = parent->floating->items[i]; | ||
69 | layout.c:309:18: for (i = 0; i < parent->children->length; ++i) { | ||
70 | layout.c:310:20: swayc_t *child = parent->children->items[i]; | ||
71 | layout.c:327:7: if (parent->type == C_OUTPUT) { | ||
72 | layout.c:338:8: if (parent->layout == L_HORIZ || parent->type == C_ROOT) { | ||
73 | layout.c:343:8: if (parent->layout == L_VERT) { | ||
74 | layout.c:350:20: for (i = 0; i < parent->children->length; ++i) { | ||
75 | layout.c:351:22: swayc_t *child = parent->children->items[i]; | ||
76 | layout.c:357:34: if (desired < 0 || desired >= parent->children->length) { | ||
77 | layout.c:360:12: return parent->children->items[desired]; | ||
78 | layout.c:365:13: parent = parent->parent; | ||
79 | |||
80 | commands.c:394:9: while (parent->type == C_VIEW) { | ||
81 | commands.c:395:12: parent = parent->parent; | ||
82 | commands.c:399:3: parent->layout = L_HORIZ; | ||
83 | commands.c:401:3: parent->layout = L_VERT; | ||
84 | commands.c:403:7: if (parent->layout == L_VERT) { | ||
85 | commands.c:404:4: parent->layout = L_HORIZ; | ||
86 | commands.c:406:4: parent->layout = L_VERT; | ||
87 | commands.c:409:26: arrange_windows(parent, parent->width, parent->height); | ||
88 | commands.c:454:10: while (parent->parent) { | ||
89 | commands.c:455:8: if (parent->parent->layout == L_HORIZ) { | ||
90 | commands.c:456:21: for (i = 0; i < parent->parent->children->length; i++) { | ||
91 | commands.c:457:16: sibling = parent->parent->children->items[i]; | ||
92 | commands.c:459:24: if (sibling->x < parent->x) { | ||
93 | commands.c:461:31: } else if (sibling->x > parent->x) { | ||
94 | commands.c:470:13: parent = parent->parent; | ||
95 | commands.c:475:87: sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); | ||
96 | commands.c:477:19: for (i = 0; i < parent->parent->children->length; i++) { | ||
97 | commands.c:478:14: sibling = parent->parent->children->items[i]; | ||
98 | commands.c:480:22: if (sibling->x < parent->x) { | ||
99 | commands.c:488:29: } else if (sibling->x > parent->x) { | ||
100 | commands.c:517:10: while (parent->parent) { | ||
101 | commands.c:518:8: if (parent->parent->layout == L_VERT) { | ||
102 | commands.c:519:21: for (i = 0; i < parent->parent->children->length; i++) { | ||
103 | commands.c:520:16: sibling = parent->parent->children->items[i]; | ||
104 | commands.c:522:24: if (sibling->y < parent->y) { | ||
105 | commands.c:524:31: } else if (sibling->y > parent->y) { | ||
106 | commands.c:533:13: parent = parent->parent; | ||
107 | commands.c:538:87: sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); | ||
108 | commands.c:540:19: for (i = 0; i < parent->parent->children->length; i++) { | ||
109 | commands.c:541:14: sibling = parent->parent->children->items[i]; | ||
110 | commands.c:543:22: if (sibling->y < parent->y) { | ||
111 | commands.c:551:29: } else if (sibling->x > parent->x) { | ||
112 | commands.c:603:54: } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { | ||
113 | commands.c:606:12: focused->parent->layout = layout; | ||