aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-09-05 20:48:52 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-09-05 20:48:52 -0700
commitf25c6b312b2f4176a1936436e23140c791919ceb (patch)
tree63537a7cb41b5e4c97cc25a243fdaf9b939fdefd
parentMerge pull request #170 from mikkeloscar/master (diff)
downloadsway-f25c6b312b2f4176a1936436e23140c791919ceb.tar.gz
sway-f25c6b312b2f4176a1936436e23140c791919ceb.tar.zst
sway-f25c6b312b2f4176a1936436e23140c791919ceb.zip
gap resize
-rw-r--r--include/container.h4
-rw-r--r--sway/commands.c131
-rw-r--r--sway/config.c1
-rw-r--r--sway/container.c21
-rw-r--r--sway/log.c5
5 files changed, 139 insertions, 23 deletions
diff --git a/include/container.h b/include/container.h
index f902950a..a9b95229 100644
--- a/include/container.h
+++ b/include/container.h
@@ -116,7 +116,9 @@ void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
116 116
117// Mappings 117// Mappings
118void set_view_visibility(swayc_t *view, void *data); 118void set_view_visibility(swayc_t *view, void *data);
119void reset_gaps(swayc_t *view, void *data); 119// Set or add to gaps
120void set_gaps(swayc_t *view, void *amount);
121void add_gaps(swayc_t *view, void *amount);
120 122
121void update_visibility(swayc_t *container); 123void update_visibility(swayc_t *container);
122 124
diff --git a/sway/commands.c b/sway/commands.c
index 0fc98538..ffe7faa4 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -517,9 +517,10 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
517 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { 517 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
518 return false; 518 return false;
519 } 519 }
520 520 const char *amount_str = argv[0];
521 if (argc == 1) { 521 // gaps amount
522 int amount = (int)strtol(argv[0], NULL, 10); 522 if (argc >= 1 && isdigit(*amount_str)) {
523 int amount = (int)strtol(amount_str, NULL, 10);
523 if (errno == ERANGE || amount == 0) { 524 if (errno == ERANGE || amount == 0) {
524 errno = 0; 525 errno = 0;
525 return false; 526 return false;
@@ -530,23 +531,127 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
530 if (config->gaps_outer == 0) { 531 if (config->gaps_outer == 0) {
531 config->gaps_outer = amount; 532 config->gaps_outer = amount;
532 } 533 }
533 } else if (argc == 2) { 534 return true;
534 int amount = (int)strtol(argv[1], NULL, 10); 535 }
536 // gaps inner|outer n
537 else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) {
538 int amount = (int)strtol(amount_str, NULL, 10);
535 if (errno == ERANGE || amount == 0) { 539 if (errno == ERANGE || amount == 0) {
536 errno = 0; 540 errno = 0;
537 return false; 541 return false;
538 } 542 }
539 if (strcasecmp(argv[0], "inner") == 0) { 543 const char *target_str = argv[0];
544 if (strcasecmp(target_str, "inner") == 0) {
540 config->gaps_inner = amount; 545 config->gaps_inner = amount;
541 } else if (strcasecmp(argv[0], "outer") == 0) { 546 } else if (strcasecmp(target_str, "outer") == 0) {
542 config->gaps_outer = amount; 547 config->gaps_outer = amount;
548 }
549 return true;
550 }
551 // gaps inner|outer current|all set|plus|minus n
552 if (argc < 4) {
553 return false;
554 }
555 // gaps inner|outer ...
556 const char *inout_str = argv[0];
557 enum {INNER, OUTER} inout;
558 if (strcasecmp(inout_str, "inner") == 0) {
559 inout = INNER;
560 } else if (strcasecmp(inout_str, "outer") == 0) {
561 inout = OUTER;
562 } else {
563 return false;
564 }
565
566 // gaps ... current|all ...
567 const char *target_str = argv[1];
568 enum {CURRENT, WORKSPACE, ALL} target;
569 if (strcasecmp(target_str, "current") == 0) {
570 target = CURRENT;
571 } else if (strcasecmp(target_str, "all") == 0) {
572 target = ALL;
573 } else if (strcasecmp(target_str, "workspace") == 0){
574 if (inout == OUTER) {
575 target = CURRENT;
543 } else { 576 } else {
544 return false; 577 // Set gap for views in workspace
578 target = WORKSPACE;
545 } 579 }
546 } else { 580 } else {
547 return false; 581 return false;
548 } 582 }
549 arrange_windows(&root_container, -1, -1); 583
584 // gaps ... n
585 amount_str = argv[3];
586 int amount = (int)strtol(amount_str, NULL, 10);
587 if (errno == ERANGE || amount == 0) {
588 errno = 0;
589 return false;
590 }
591
592 // gaps ... set|plus|minus ...
593 const char *method_str = argv[2];
594 enum {SET, ADD} method;
595 if (strcasecmp(method_str, "set") == 0) {
596 method = SET;
597 } else if (strcasecmp(method_str, "plus") == 0) {
598 method = ADD;
599 } else if (strcasecmp(method_str, "minus") == 0) {
600 method = ADD;
601 amount *= -1;
602 } else {
603 return false;
604 }
605
606 if (target == CURRENT) {
607 swayc_t *cont;
608 if (inout == OUTER) {
609 if ((cont = swayc_active_workspace()) == NULL) {
610 return false;
611 }
612 } else {
613 if ((cont = get_focused_view(&root_container))->type != C_VIEW) {
614 return false;
615 }
616 }
617 cont->gaps = swayc_gap(cont);
618 if (method == SET) {
619 cont->gaps = amount;
620 } else if ((cont->gaps += amount) < 0) {
621 cont->gaps = 0;
622 }
623 arrange_windows(cont->parent, -1, -1);
624 } else if (inout == OUTER) {
625 //resize all workspace.
626 int i,j;
627 for (i = 0; i < root_container.children->length; ++i) {
628 swayc_t *op = root_container.children->items[i];
629 for (j = 0; j < op->children->length; ++j) {
630 swayc_t *ws = op->children->items[j];
631 if (method == SET) {
632 ws->gaps = amount;
633 } else if ((ws->gaps += amount) < 0) {
634 ws->gaps = 0;
635 }
636 }
637 }
638 arrange_windows(&root_container, -1, -1);
639 } else {
640 // Resize gaps for all views in workspace
641 swayc_t *top;
642 if (target == WORKSPACE) {
643 if ((top = swayc_active_workspace()) == NULL) {
644 return false;
645 }
646 } else {
647 top = &root_container;
648 }
649 int top_gap = top->gaps;
650 container_map(top, method == SET ? set_gaps : add_gaps, &amount);
651 top->gaps = top_gap;
652 arrange_windows(top, -1, -1);
653 }
654
550 return true; 655 return true;
551} 656}
552 657
@@ -975,10 +1080,10 @@ bool handle_command(struct sway_config *config, char *exec) {
975 char **argv = split_directive(exec + strlen(handler->command), &argc); 1080 char **argv = split_directive(exec + strlen(handler->command), &argc);
976 int i; 1081 int i;
977 1082
978 // Perform var subs on all parts of the command 1083 // Perform var subs on all parts of the command
979 for (i = 0; i < argc; ++i) { 1084 for (i = 0; i < argc; ++i) {
980 argv[i] = do_var_replacement(config, argv[i]); 1085 argv[i] = do_var_replacement(config, argv[i]);
981 } 1086 }
982 1087
983 exec_success = handler->handle(config, argc, argv); 1088 exec_success = handler->handle(config, argc, argv);
984 for (i = 0; i < argc; ++i) { 1089 for (i = 0; i < argc; ++i) {
diff --git a/sway/config.c b/sway/config.c
index 90f6529a..c9a9cc74 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -246,7 +246,6 @@ _continue:
246 246
247 if (is_active) { 247 if (is_active) {
248 temp_config->reloading = false; 248 temp_config->reloading = false;
249 container_map(&root_container, reset_gaps, NULL);
250 arrange_windows(&root_container, -1, -1); 249 arrange_windows(&root_container, -1, -1);
251 } 250 }
252 config = temp_config; 251 config = temp_config;
diff --git a/sway/container.c b/sway/container.c
index c922a6e6..ef0e6c55 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -653,15 +653,24 @@ void update_visibility(swayc_t *container) {
653 } 653 }
654} 654}
655 655
656void reset_gaps(swayc_t *view, void *data) { 656void set_gaps(swayc_t *view, void *_data) {
657 (void) data; 657 int *data = _data;
658 if (!ASSERT_NONNULL(view)) { 658 if (!ASSERT_NONNULL(view)) {
659 return; 659 return;
660 } 660 }
661 if (view->type == C_WORKSPACE) { 661 if (view->type == C_WORKSPACE || view->type == C_VIEW) {
662 view->gaps = -1; 662 view->gaps = *data;
663 } 663 }
664 if (view->type == C_VIEW) { 664}
665 view->gaps = -1; 665
666void add_gaps(swayc_t *view, void *_data) {
667 int *data = _data;
668 if (!ASSERT_NONNULL(view)) {
669 return;
670 }
671 if (view->type == C_WORKSPACE || view->type == C_VIEW) {
672 if ((view->gaps += *data) < 0) {
673 view->gaps = 0;
674 }
666 } 675 }
667} 676}
diff --git a/sway/log.c b/sway/log.c
index fed1239c..cf5c2092 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -159,8 +159,9 @@ static void container_log(const swayc_t *c) {
159 c->layout == L_STACKED ? "Stacked|": 159 c->layout == L_STACKED ? "Stacked|":
160 c->layout == L_FLOATING ? "Floating|": 160 c->layout == L_FLOATING ? "Floating|":
161 "Unknown|"); 161 "Unknown|");
162 fprintf(stderr, "w:%f|h:%f|", c->width, c->height); 162 fprintf(stderr, "w:%.f|h:%.f|", c->width, c->height);
163 fprintf(stderr, "x:%f|y:%f|", c->x, c->y); 163 fprintf(stderr, "x:%.f|y:%.f|", c->x, c->y);
164 fprintf(stderr, "g:%d|",c->gaps);
164 fprintf(stderr, "vis:%c|", c->visible?'t':'f'); 165 fprintf(stderr, "vis:%c|", c->visible?'t':'f');
165 fprintf(stderr, "name:%.16s|", c->name); 166 fprintf(stderr, "name:%.16s|", c->name);
166 fprintf(stderr, "children:%d\n",c->children?c->children->length:0); 167 fprintf(stderr, "children:%d\n",c->children?c->children->length:0);