From 6271abd644da15070d29d2d06bc527f89a799375 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 8 Oct 2017 11:26:45 -0400 Subject: [PATCH] Fix #1291 --- sway/commands/scratchpad.c | 14 ++++++++++---- sway/criteria.c | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c index dec32f518..6c5c92df2 100644 --- a/sway/commands/scratchpad.c +++ b/sway/commands/scratchpad.c @@ -7,10 +7,8 @@ #include "sway/layout.h" static swayc_t *fetch_view_from_scratchpad() { - if (sp_index >= scratchpad->length) { - sp_index = 0; - } - swayc_t *view = scratchpad->items[sp_index++]; + sp_index = (sp_index + 1) % scratchpad->length; + swayc_t *view = scratchpad->items[sp_index]; if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) { wlc_view_set_output(view->handle, swayc_active_output()->handle); @@ -46,6 +44,14 @@ struct cmd_results *cmd_scratchpad(int argc, char **argv) { if (strcasecmp(argv[0], "show") == 0 && scratchpad->length > 0) { if (!sp_view) { + if (current_container) { + // Haxor the scratchpad index if criteria'd + for (int i = 0; i < scratchpad->length; ++i) { + if (scratchpad->items[i] == current_container) { + sp_index = (i - 1) % scratchpad->length; + } + } + } sp_view = fetch_view_from_scratchpad(); } else { if (swayc_active_workspace() != sp_view->parent) { diff --git a/sway/criteria.c b/sway/criteria.c index f5fe40cbf..e8978ebef 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -434,10 +434,18 @@ static void container_match_add(swayc_t *container, struct list_tokens *list_tok list_add(list_tokens->list, container); } } + list_t *container_for(list_t *tokens) { struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens}; container_map(&root_container, (void (*)(swayc_t *, void *))container_match_add, &list_tokens); + + for (int i = 0; i < scratchpad->length; ++i) { + swayc_t *c = scratchpad->items[i]; + if (criteria_test(c, tokens)) { + list_add(list_tokens.list, c); + } + } return list_tokens.list; }