diff --git a/include/layout.h b/include/layout.h index dfee512ed..7d18108cb 100644 --- a/include/layout.h +++ b/include/layout.h @@ -32,4 +32,9 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed void view_set_floating(swayc_t *view, bool floating); +// Scratchpad + +void scratchpad_push(swayc_t *view); +swayc_t *scratchpad_pop(void); + #endif diff --git a/sway/commands.c b/sway/commands.c index 27dd9ff48..39776d89e 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -200,13 +200,13 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { swayc_t *view = get_focused_container(&root_container); bool floating; - if (strcasecmp(argv[0], "toggle") != 0) { + if (strcasecmp(argv[0], "toggle") == 0) { floating = !view->is_floating; } - else if (strcasecmp(argv[0], "enable") != 0) { + else if (strcasecmp(argv[0], "enable") == 0) { floating = true; } - else if (strcasecmp(argv[0], "disable") != 0) { + else if (strcasecmp(argv[0], "disable") == 0) { floating = false; } else { @@ -326,12 +326,36 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { move_container(view,&root_container,MOVE_UP); } else if (strcasecmp(argv[0], "down") == 0) { move_container(view,&root_container,MOVE_DOWN); + } else if (strcasecmp(argv[0], "scratchpad") == 0) { + swayc_t *parent = view->parent; + destroy_container(remove_child(view)); + scratchpad_push(view); + set_focused_container(parent); } else { return false; } return true; } +static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) { + if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) { + return false; + } + + if (strcasecmp(argv[0], "show") != 0) { + sway_log(L_ERROR, "scratchpad - unknown token '%s', expected show", argv[0]); + return false; + } + + swayc_t *view = scratchpad_pop(); + if (view == NULL) { + return false; + } + view_set_floating(view, true); + + return true; +} + static bool cmd_output(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { return false; @@ -668,6 +692,7 @@ static struct cmd_handler handlers[] = { { "output", cmd_output}, { "reload", cmd_reload }, { "resize", cmd_resize }, + { "scratchpad", cmd_scratchpad }, { "set", cmd_set }, { "split", cmd_split }, { "splith", cmd_splith }, diff --git a/sway/layout.c b/sway/layout.c index 1b78e15ed..6b7bdae34 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -14,11 +14,15 @@ swayc_t root_container; int min_sane_h = 60; int min_sane_w = 100; +static swayc_t *scratchpad = NULL; + void init_layout(void) { root_container.type = C_ROOT; root_container.layout = L_NONE; root_container.children = create_list(); root_container.handle = -1; + + scratchpad = new_workspace(&root_container, "__i3_scratch"); } static int index_child(swayc_t *parent, swayc_t *child) { @@ -464,3 +468,16 @@ void view_set_floating(swayc_t *view, bool floating) { arrange_windows(swayc_active_workspace(), -1, -1); } } + +void scratchpad_push(swayc_t *view) { + add_floating(scratchpad, view); +} + +swayc_t *scratchpad_pop(void) { + if (scratchpad->floating->length == 0) { + return NULL; + } + swayc_t *view = scratchpad->floating->items[0]; + remove_child(view); + return view; +}