summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 42105d5f..6a4af43c 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -23,6 +23,7 @@
23#include "sway.h" 23#include "sway.h"
24#include "resize.h" 24#include "resize.h"
25#include "input_state.h" 25#include "input_state.h"
26#include "criteria.h"
26 27
27typedef struct cmd_results *sway_cmd(int argc, char **argv); 28typedef struct cmd_results *sway_cmd(int argc, char **argv);
28 29
@@ -41,6 +42,7 @@ static sway_cmd cmd_floating;
41static sway_cmd cmd_floating_mod; 42static sway_cmd cmd_floating_mod;
42static sway_cmd cmd_focus; 43static sway_cmd cmd_focus;
43static sway_cmd cmd_focus_follows_mouse; 44static sway_cmd cmd_focus_follows_mouse;
45static sway_cmd cmd_for_window;
44static sway_cmd cmd_fullscreen; 46static sway_cmd cmd_fullscreen;
45static sway_cmd cmd_gaps; 47static sway_cmd cmd_gaps;
46static sway_cmd cmd_kill; 48static sway_cmd cmd_kill;
@@ -1241,6 +1243,37 @@ static struct cmd_results *cmd_log_colors(int argc, char **argv) {
1241 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1243 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1242} 1244}
1243 1245
1246static struct cmd_results *cmd_for_window(int argc, char **argv) {
1247 struct cmd_results *error = NULL;
1248 if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) {
1249 return error;
1250 }
1251 // add command to a criteria/command pair that is run against views when they appear.
1252 char *criteria = argv[0], *cmdlist = join_args(argv + 1, argc - 1);
1253
1254 struct criteria *crit = malloc(sizeof(struct criteria));
1255 crit->crit_raw = strdup(criteria);
1256 crit->cmdlist = cmdlist;
1257 crit->tokens = create_list();
1258 char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
1259
1260 if (err_str) {
1261 error = cmd_results_new(CMD_INVALID, "for_window", err_str);
1262 free(err_str);
1263 free_criteria(crit);
1264 } else if (crit->tokens->length == 0) {
1265 error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria");
1266 free_criteria(crit);
1267 } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
1268 sway_log(L_DEBUG, "for_window: Duplicate, skipping.");
1269 free_criteria(crit);
1270 } else {
1271 sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
1272 list_add(config->criteria, crit);
1273 }
1274 return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
1275}
1276
1244static struct cmd_results *cmd_fullscreen(int argc, char **argv) { 1277static struct cmd_results *cmd_fullscreen(int argc, char **argv) {
1245 struct cmd_results *error = NULL; 1278 struct cmd_results *error = NULL;
1246 if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file."); 1279 if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file.");
@@ -1353,6 +1386,7 @@ static struct cmd_handler handlers[] = {
1353 { "floating_modifier", cmd_floating_mod }, 1386 { "floating_modifier", cmd_floating_mod },
1354 { "focus", cmd_focus }, 1387 { "focus", cmd_focus },
1355 { "focus_follows_mouse", cmd_focus_follows_mouse }, 1388 { "focus_follows_mouse", cmd_focus_follows_mouse },
1389 { "for_window", cmd_for_window },
1356 { "fullscreen", cmd_fullscreen }, 1390 { "fullscreen", cmd_fullscreen },
1357 { "gaps", cmd_gaps }, 1391 { "gaps", cmd_gaps },
1358 { "kill", cmd_kill }, 1392 { "kill", cmd_kill },