summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-29 21:14:13 -0500
committerLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-29 21:14:13 -0500
commit28e937020abe440e3ad803330c91fc52a05d87fe (patch)
tree708d4a368dae858e73100f58567edabcd839e028
parent#151 fix (diff)
downloadsway-28e937020abe440e3ad803330c91fc52a05d87fe.tar.gz
sway-28e937020abe440e3ad803330c91fc52a05d87fe.tar.zst
sway-28e937020abe440e3ad803330c91fc52a05d87fe.zip
Made scratchpad handling identical to i3
-rw-r--r--include/commands.h2
-rw-r--r--sway/commands.c107
-rw-r--r--sway/handlers.c1
3 files changed, 91 insertions, 19 deletions
diff --git a/include/commands.h b/include/commands.h
index c2046e13..714d2db0 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -10,4 +10,6 @@ struct cmd_handler {
10 10
11bool handle_command(struct sway_config *config, char *command); 11bool handle_command(struct sway_config *config, char *command);
12 12
13void remove_view_from_scratchpad();
14
13#endif 15#endif
diff --git a/sway/commands.c b/sway/commands.c
index b123b5dc..c31911de 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -23,6 +23,9 @@ struct modifier_key {
23 uint32_t mod; 23 uint32_t mod;
24}; 24};
25 25
26swayc_t *sp_view;
27int sp_index = 0;
28
26static struct modifier_key modifiers[] = { 29static struct modifier_key modifiers[] = {
27 { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, 30 { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT },
28 { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, 31 { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS },
@@ -246,6 +249,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
246 // Refocus on the view once its been put back into the layout 249 // Refocus on the view once its been put back into the layout
247 view->width = view->height = 0; 250 view->width = view->height = 0;
248 arrange_windows(swayc_active_workspace(), -1, -1); 251 arrange_windows(swayc_active_workspace(), -1, -1);
252 remove_view_from_scratchpad(view);
249 } 253 }
250 set_focused_container(view); 254 set_focused_container(view);
251 } 255 }
@@ -343,6 +347,22 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char *
343 return true; 347 return true;
344} 348}
345 349
350static void hide_view_in_scratchpad(swayc_t *sp_view) {
351 if(sp_view == NULL) {
352 return;
353 }
354
355 wlc_view_set_mask(sp_view->handle, 0);
356 sp_view->visible = false;
357 swayc_t *ws = sp_view->parent;
358 remove_child(sp_view);
359 if (swayc_active_workspace() != ws && ws->floating->length == 0 && ws->children->length == 0) {
360 destroy_workspace(ws);
361 }
362 arrange_windows(ws, -1, -1);
363 set_focused_container(container_under_pointer());
364}
365
346static bool cmd_move(struct sway_config *config, int argc, char **argv) { 366static bool cmd_move(struct sway_config *config, int argc, char **argv) {
347 if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { 367 if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) {
348 return false; 368 return false;
@@ -386,6 +406,14 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
386 return false; 406 return false;
387 } 407 }
388 swayc_t *view = get_focused_container(&root_container); 408 swayc_t *view = get_focused_container(&root_container);
409 int i;
410 for (i = 0; i < scratchpad->length; i++) {
411 if (scratchpad->items[i] == view) {
412 hide_view_in_scratchpad(view);
413 sp_view = NULL;
414 return true;
415 }
416 }
389 list_add(scratchpad, view); 417 list_add(scratchpad, view);
390 if (!view->is_floating) { 418 if (!view->is_floating) {
391 destroy_container(remove_child(view)); 419 destroy_container(remove_child(view));
@@ -590,30 +618,71 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
590 return false; 618 return false;
591} 619}
592 620
621static swayc_t *fetch_view_from_scratchpad() {
622 if (sp_index >= scratchpad->length) {
623 sp_index = 0;
624 }
625 swayc_t *view = scratchpad->items[sp_index++];
626
627 if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) {
628 wlc_view_set_output(view->handle, swayc_active_output()->handle);
629 }
630 if (!view->is_floating) {
631 view->width = swayc_active_workspace()->width/2;
632 view->height = swayc_active_workspace()->height/2;
633 view->x = (swayc_active_workspace()->width - view->width)/2;
634 view->y = (swayc_active_workspace()->height - view->height)/2;
635 }
636 if (swayc_active_workspace()->width < view->x + 20 || view->x + view->width < 20) {
637 view->x = (swayc_active_workspace()->width - view->width)/2;
638 }
639 if (swayc_active_workspace()->height < view->y + 20 || view->y + view->height < 20) {
640 view->y = (swayc_active_workspace()->height - view->height)/2;
641 }
642
643 add_floating(swayc_active_workspace(), view);
644 wlc_view_set_mask(view->handle, VISIBLE);
645 view->visible = true;
646 arrange_windows(swayc_active_workspace(), -1, -1);
647 set_focused_container(view);
648 return view;
649}
650
651void remove_view_from_scratchpad(swayc_t *view) {
652 int i;
653 for (i = 0; i < scratchpad->length; i++) {
654 if (scratchpad->items[i] == view) {
655 if (sp_index == 0) {
656 sp_index = scratchpad->length - 1;
657 } else {
658 sp_index--;
659 }
660 list_del(scratchpad, sp_index);
661 sp_view = NULL;
662 }
663 }
664}
665
593static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) { 666static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) {
594 if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) { 667 if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) {
595 return false; 668 return false;
596 } 669 }
597 if (strcasecmp(argv[0], "show") == 0) { 670
598 if (scratchpad->length > 0) { 671 if (strcasecmp(argv[0], "show") == 0 && scratchpad->length > 0) {
599 swayc_t *view = scratchpad->items[0]; 672 if (!sp_view) {
600 list_del(scratchpad, 0); 673 sp_view = fetch_view_from_scratchpad();
601 add_floating(swayc_active_workspace(), view); 674 } else {
602 view->x = (swayc_active_workspace()->width - view->width)/2; 675 if (swayc_active_workspace() != sp_view->parent) {
603 view->y = (swayc_active_workspace()->height - view->height)/2; 676 hide_view_in_scratchpad(sp_view);
604 if (view->desired_width != -1) { 677 if (sp_index == 0) {
605 view->width = view->desired_width; 678 sp_index = scratchpad->length;
606 } 679 }
607 if (view->desired_height != -1) { 680 sp_index--;
608 view->height = view->desired_height; 681 sp_view = fetch_view_from_scratchpad();
609 } 682 } else {
610 wlc_view_set_mask(view->handle, VISIBLE); 683 hide_view_in_scratchpad(sp_view);
611 arrange_windows(swayc_active_workspace(), -1, -1); 684 sp_view = NULL;
612 swayc_t *focused = container_under_pointer();
613 if (focused == NULL) {
614 focused = swayc_active_workspace();
615 } 685 }
616 set_focused_container(focused);
617 } 686 }
618 return true; 687 return true;
619 } else { 688 } else {
diff --git a/sway/handlers.c b/sway/handlers.c
index d0b129e8..4c21c6b9 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -237,6 +237,7 @@ static void handle_view_destroyed(wlc_handle handle) {
237 case WLC_BIT_POPUP: 237 case WLC_BIT_POPUP:
238 if (view) { 238 if (view) {
239 swayc_t *parent = destroy_view(view); 239 swayc_t *parent = destroy_view(view);
240 remove_view_from_scratchpad(view);
240 arrange_windows(parent, -1, -1); 241 arrange_windows(parent, -1, -1);
241 } 242 }
242 break; 243 break;