aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/for_window.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-09 14:23:20 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-11 09:38:53 +1000
commit3b0c26d149dfe5e05df338692db8255a01f0998d (patch)
treec39e377cb96297df8547311a0aa4cfe8fa85b517 /sway/commands/for_window.c
parentMerge pull request #1948 from RyanDwyer/focus-parent-border (diff)
downloadsway-3b0c26d149dfe5e05df338692db8255a01f0998d.tar.gz
sway-3b0c26d149dfe5e05df338692db8255a01f0998d.tar.zst
sway-3b0c26d149dfe5e05df338692db8255a01f0998d.zip
Overhaul criteria implementation
The criteria struct now uses properties for each token type rather than the list_t list of tokens. The reason for this is that different token types have different data types: pcre, string and number to name a few. This solution should be more flexible moving forward. A bonus of this is that criteria is now easier to understand when looking at the struct definition. The criteria parser has been rewritten because the previous one didn't support valueless pairs (eg. [class="foo" floating]). Criteria now has types. Types at the moment are CT_COMMAND, CT_ASSIGN_WORKSPACE and CT_ASSIGN_OUTPUT. i3 uses types as well. Previously the assign command was creating a criteria with 'move to workspace <name>' as its command, but this caused the window to appear briefly on the focused workspace before being moved to the assigned workspace. It now creates the view directly in the assigned workspace. Each view will only execute a given criteria once. This is achieved by storing a list of executed criteria in the view. This is the same strategy used by i3. Escaping now works properly. Previously you could do things like [class="Fire\"fox"] and the stored value would be 'Fire\"fox', but it should be (and now is) 'Fire"fox'. The public functions in criteria.c are now all prefixed with criteria_. Xwayland views now listen to the set_title, set_class and set_window_type events and criteria will be run when these happen. XDG shell has none of these events so it continues to update the title in handle_commit. Each view type's get_prop function has been split into get_string_prop and get_int_prop because some properties like the X11 window ID and window type are numeric. The following new criteria tokens are now supported: * id (X11 window ID) * instance * tiling * workspace
Diffstat (limited to 'sway/commands/for_window.c')
-rw-r--r--sway/commands/for_window.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/sway/commands/for_window.c b/sway/commands/for_window.c
index dd5461f0..8c425a1d 100644
--- a/sway/commands/for_window.c
+++ b/sway/commands/for_window.c
@@ -11,31 +11,20 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
11 if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { 11 if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) {
12 return error; 12 return error;
13 } 13 }
14 // add command to a criteria/command pair that is run against views when they appear.
15 char *criteria = argv[0], *cmdlist = join_args(argv + 1, argc - 1);
16 14
17 struct criteria *crit = calloc(sizeof(struct criteria), 1); 15 char *err_str = NULL;
18 if (!crit) { 16 struct criteria *criteria = criteria_parse(argv[0], &err_str);
19 return cmd_results_new(CMD_FAILURE, "for_window", "Unable to allocate criteria"); 17 if (!criteria) {
20 }
21 crit->crit_raw = strdup(criteria);
22 crit->cmdlist = cmdlist;
23 crit->tokens = create_list();
24 char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
25
26 if (err_str) {
27 error = cmd_results_new(CMD_INVALID, "for_window", err_str); 18 error = cmd_results_new(CMD_INVALID, "for_window", err_str);
28 free(err_str); 19 free(err_str);
29 free_criteria(crit); 20 return error;
30 } else if (crit->tokens->length == 0) {
31 error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria");
32 free_criteria(crit);
33 } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
34 wlr_log(L_DEBUG, "for_window: Duplicate, skipping.");
35 free_criteria(crit);
36 } else {
37 wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
38 list_add(config->criteria, crit);
39 } 21 }
40 return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); 22
23 criteria->type = CT_COMMAND;
24 criteria->cmdlist = join_args(argv + 1, argc - 1);
25
26 list_add(config->criteria, criteria);
27 wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist);
28
29 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
41} 30}