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).
This commit is contained in:
Daniel De Graaf 2020-09-02 22:01:49 -04:00
parent 9c30140b0a
commit 7bf8c3ead0
3 changed files with 18 additions and 2 deletions

View file

@ -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;

View file

@ -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

View file

@ -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) {