From 7bf8c3ead009732bc355c6bea385a7a0e976d4bd Mon Sep 17 00:00:00 2001 From: Daniel De Graaf Date: Wed, 2 Sep 2020 22:01:49 -0400 Subject: [PATCH] Add for_window --always This allows a for_window command to trigger multiple times on the same window; the default is to only run the command once (when it first matches). This can be useful to apply rules to applications like VLC that hide and show a window without re-creating it (when using the taskbar icon to hide/show). --- include/sway/criteria.h | 1 + sway/commands/for_window.c | 14 ++++++++++++++ sway/tree/view.c | 5 +++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 79386a0d7..0a0e61504 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -45,6 +45,7 @@ struct criteria { #endif bool floating; bool tiling; + bool always; char urgent; // 'l' for latest or 'o' for oldest struct pattern *workspace; pid_t pid; diff --git a/sway/commands/for_window.c b/sway/commands/for_window.c index ee9f46478..f61abf399 100644 --- a/sway/commands/for_window.c +++ b/sway/commands/for_window.c @@ -6,6 +6,19 @@ #include "stringop.h" struct cmd_results *cmd_for_window(int argc, char **argv) { + bool always = false; + while (argc > 0) { + if (strcmp("--always", argv[0]) == 0) { + always = true; + } else if (strcmp("--once", argv[0]) == 0) { + always = false; + } else { + break; + } + argv++; + argc--; + } + struct cmd_results *error = NULL; if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { return error; @@ -20,6 +33,7 @@ struct cmd_results *cmd_for_window(int argc, char **argv) { } criteria->type = CT_COMMAND; + criteria->always = always; criteria->cmdlist = join_args(argv + 1, argc - 1); // Check if it already exists diff --git a/sway/tree/view.c b/sway/tree/view.c index 4debcae23..592beedf3 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -488,13 +488,14 @@ void view_execute_criteria(struct sway_view *view, const char* trigger) { for (int i = 0; i < criterias->length; i++) { struct criteria *criteria = criterias->items[i]; sway_log(SWAY_DEBUG, "Checking criteria %s", criteria->raw); - if (view_has_executed_criteria(view, criteria)) { + if (!criteria->always && view_has_executed_criteria(view, criteria)) { sway_log(SWAY_DEBUG, "Criteria already executed"); continue; } sway_log(SWAY_DEBUG, "for_window '%s' matches view %p, cmd: '%s'", criteria->raw, view, criteria->cmdlist); - list_add(view->executed_criteria, criteria); + if (!criteria->always) + list_add(view->executed_criteria, criteria); list_t *res_list = execute_command( criteria->cmdlist, NULL, view->container); while (res_list->length) {