From a06cb7cd01acfbb5e31dd1aacbbde7887a0509b9 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Tue, 17 Nov 2015 19:27:01 +0100 Subject: criteria: Add. Learn for_window command. A criteria is a string in the form of `[class="regex.*" title="str"]`. It is stored in a struct with a list of *tokens* which is a attribute/value pair (stored as a `crit_token` struct). Most tokens will also have a precompiled regex stored that will be used during criteria matching. for_window command: When a new view is created its metadata is tested against all stored criteria, and if a match is found the associated command list is executed. Unfortunately some metadata is not available in sway at the moment (specifically `instance`, `window_role` and `urgent`). Any criteria string that tries to match an unsupported attribute will fail. (Note that while the criteria code can be used to parse any criteria string it is currently only used by the `for_window` command.) --- include/config.h | 1 + include/criteria.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 include/criteria.h (limited to 'include') diff --git a/include/config.h b/include/config.h index 3bdbdb7b..6b48063a 100644 --- a/include/config.h +++ b/include/config.h @@ -66,6 +66,7 @@ struct sway_config { list_t *cmd_queue; list_t *workspace_outputs; list_t *output_configs; + list_t *criteria; struct sway_mode *current_mode; uint32_t floating_mod; enum swayc_layouts default_orientation; diff --git a/include/criteria.h b/include/criteria.h new file mode 100644 index 00000000..5c71d172 --- /dev/null +++ b/include/criteria.h @@ -0,0 +1,36 @@ +#ifndef _SWAY_CRITERIA_H +#define _SWAY_CRITERIA_H + +#include "container.h" +#include "list.h" + +/** + * Maps criteria (as a list of criteria tokens) to a command list. + * + * A list of tokens together represent a single criteria string (e.g. + * '[class="abc" title="xyz"]' becomes two criteria tokens). + * + * for_window: Views matching all criteria will have the bound command list + * executed on them. + * + * Set via `for_window `. + */ +struct criteria { + list_t *tokens; // struct crit_token, contains compiled regex. + char *crit_raw; // entire criteria string (for logging) + + char *cmdlist; +}; + +int criteria_cmp(const void *item, const void *data); +void free_criteria(struct criteria *crit); + +// Pouplate list with crit_tokens extracted from criteria string, returns error +// string or NULL if successful. +char *extract_crit_tokens(list_t *tokens, const char *criteria); + +// Returns list of criteria that match given container. These criteria have +// been set with `for_window` commands and have an associated cmdlist. +list_t *criteria_for(swayc_t *cont); + +#endif -- cgit v1.2.3