aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/no_focus.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-04-26 17:20:12 -0400
committerGitHub <noreply@github.com>2017-04-26 17:20:12 -0400
commit11b4c3454c65375db88901165f0a69c978e3977f (patch)
tree97fabe0d36c2c5574a2ff47238eeed58fa200fd0 /sway/commands/no_focus.c
parent3c1fc00f12e2777f6349a5d671b8d66c5997eb2b (diff)
parent537261f23f194e152c0adf25a2740375929e9cd3 (diff)
Merge pull request #1196 from SirCmpwn/no_focus
Implement no_focus
Diffstat (limited to 'sway/commands/no_focus.c')
-rw-r--r--sway/commands/no_focus.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/sway/commands/no_focus.c b/sway/commands/no_focus.c
new file mode 100644
index 00000000..b3b88e5a
--- /dev/null
+++ b/sway/commands/no_focus.c
@@ -0,0 +1,41 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include "sway/commands.h"
+#include "sway/criteria.h"
+#include "list.h"
+#include "log.h"
+#include "stringop.h"
+
+struct cmd_results *cmd_no_focus(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "no_focus", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ // add command to a criteria/command pair that is run against views when they appear.
+ char *criteria = argv[0];
+
+ struct criteria *crit = malloc(sizeof(struct criteria));
+ if (!crit) {
+ return cmd_results_new(CMD_FAILURE, "no_focus", "Unable to allocate criteria");
+ }
+ crit->crit_raw = strdup(criteria);
+ crit->tokens = create_list();
+ crit->cmdlist = NULL;
+ char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
+
+ if (err_str) {
+ error = cmd_results_new(CMD_INVALID, "no_focus", err_str);
+ free(err_str);
+ free_criteria(crit);
+ } else if (crit->tokens->length == 0) {
+ error = cmd_results_new(CMD_INVALID, "no_focus", "Found no name/value pairs in criteria");
+ free_criteria(crit);
+ } else if (list_seq_find(config->no_focus, criteria_cmp, crit) != -1) {
+ sway_log(L_DEBUG, "no_focus: Duplicate, skipping.");
+ free_criteria(crit);
+ } else {
+ sway_log(L_DEBUG, "no_focus: '%s' added", crit->crit_raw);
+ list_add(config->no_focus, crit);
+ }
+ return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}