aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-29 06:51:16 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-29 06:51:16 -0400
commit6b962ebd22767a6c3fa9317ef1fdc814d195854a (patch)
tree9712d5f68fee99ead21b6f0769d325d427a2dc30
parent#149 change focus before pointer_mode (diff)
parentFixed move scratchpad and added in scratchpad show (diff)
downloadsway-6b962ebd22767a6c3fa9317ef1fdc814d195854a.tar.gz
sway-6b962ebd22767a6c3fa9317ef1fdc814d195854a.tar.zst
sway-6b962ebd22767a6c3fa9317ef1fdc814d195854a.zip
Merge pull request #150 from Luminarys/master
Added in Scratchpad
-rw-r--r--include/layout.h2
-rw-r--r--sway/commands.c52
-rw-r--r--sway/layout.c20
3 files changed, 69 insertions, 5 deletions
diff --git a/include/layout.h b/include/layout.h
index f462bdb3..cb38a7b1 100644
--- a/include/layout.h
+++ b/include/layout.h
@@ -8,6 +8,8 @@
8 8
9extern swayc_t root_container; 9extern swayc_t root_container;
10 10
11extern list_t *scratchpad;
12
11extern int min_sane_w; 13extern int min_sane_w;
12extern int min_sane_h; 14extern int min_sane_h;
13 15
diff --git a/sway/commands.c b/sway/commands.c
index 8a790384..b123b5dc 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -344,7 +344,7 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char *
344} 344}
345 345
346static bool cmd_move(struct sway_config *config, int argc, char **argv) { 346static bool cmd_move(struct sway_config *config, int argc, char **argv) {
347 if (!checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1)) { 347 if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) {
348 return false; 348 return false;
349 } 349 }
350 350
@@ -381,6 +381,24 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
381 ws = workspace_create(ws_name); 381 ws = workspace_create(ws_name);
382 } 382 }
383 move_container_to(view, get_focused_container(ws)); 383 move_container_to(view, get_focused_container(ws));
384 } else if (strcasecmp(argv[0], "scratchpad") == 0) {
385 if (view->type != C_CONTAINER && view->type != C_VIEW) {
386 return false;
387 }
388 swayc_t *view = get_focused_container(&root_container);
389 list_add(scratchpad, view);
390 if (!view->is_floating) {
391 destroy_container(remove_child(view));
392 } else {
393 remove_child(view);
394 }
395 wlc_view_set_mask(view->handle, 0);
396 arrange_windows(swayc_active_workspace(), -1, -1);
397 swayc_t *focused = container_under_pointer();
398 if (focused == NULL) {
399 focused = swayc_active_workspace();
400 }
401 set_focused_container(focused);
384 } else { 402 } else {
385 return false; 403 return false;
386 } 404 }
@@ -572,6 +590,37 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
572 return false; 590 return false;
573} 591}
574 592
593static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) {
594 if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) {
595 return false;
596 }
597 if (strcasecmp(argv[0], "show") == 0) {
598 if (scratchpad->length > 0) {
599 swayc_t *view = scratchpad->items[0];
600 list_del(scratchpad, 0);
601 add_floating(swayc_active_workspace(), view);
602 view->x = (swayc_active_workspace()->width - view->width)/2;
603 view->y = (swayc_active_workspace()->height - view->height)/2;
604 if (view->desired_width != -1) {
605 view->width = view->desired_width;
606 }
607 if (view->desired_height != -1) {
608 view->height = view->desired_height;
609 }
610 wlc_view_set_mask(view->handle, VISIBLE);
611 arrange_windows(swayc_active_workspace(), -1, -1);
612 swayc_t *focused = container_under_pointer();
613 if (focused == NULL) {
614 focused = swayc_active_workspace();
615 }
616 set_focused_container(focused);
617 }
618 return true;
619 } else {
620 return false;
621 }
622}
623
575static bool cmd_set(struct sway_config *config, int argc, char **argv) { 624static bool cmd_set(struct sway_config *config, int argc, char **argv) {
576 if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { 625 if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) {
577 return false; 626 return false;
@@ -742,6 +791,7 @@ static struct cmd_handler handlers[] = {
742 { "output", cmd_output}, 791 { "output", cmd_output},
743 { "reload", cmd_reload }, 792 { "reload", cmd_reload },
744 { "resize", cmd_resize }, 793 { "resize", cmd_resize },
794 { "scratchpad", cmd_scratchpad },
745 { "set", cmd_set }, 795 { "set", cmd_set },
746 { "split", cmd_split }, 796 { "split", cmd_split },
747 { "splith", cmd_splith }, 797 { "splith", cmd_splith },
diff --git a/sway/layout.c b/sway/layout.c
index b558e704..875115e7 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -10,6 +10,7 @@
10#include "focus.h" 10#include "focus.h"
11 11
12swayc_t root_container; 12swayc_t root_container;
13list_t *scratchpad;
13 14
14int min_sane_h = 60; 15int min_sane_h = 60;
15int min_sane_w = 100; 16int min_sane_w = 100;
@@ -20,14 +21,25 @@ void init_layout(void) {
20 root_container.children = create_list(); 21 root_container.children = create_list();
21 root_container.handle = -1; 22 root_container.handle = -1;
22 root_container.visible = true; 23 root_container.visible = true;
24 scratchpad = create_list();
23} 25}
24 26
25int index_child(const swayc_t *child) { 27int index_child(const swayc_t *child) {
26 swayc_t *parent = child->parent; 28 swayc_t *parent = child->parent;
27 int i, len = parent->children->length; 29 int i, len;
28 for (i = 0; i < len; ++i) { 30 if (!child->is_floating) {
29 if (parent->children->items[i] == child) { 31 len = parent->children->length;
30 break; 32 for (i = 0; i < len; ++i) {
33 if (parent->children->items[i] == child) {
34 break;
35 }
36 }
37 } else {
38 len = parent->floating->length;
39 for (i = 0; i < len; ++i) {
40 if (parent->floating->items[i] == child) {
41 break;
42 }
31 } 43 }
32 } 44 }
33 if (!sway_assert(i < len, "Stray container")) { 45 if (!sway_assert(i < len, "Stray container")) {