cmd_assign

This implements cmd_assign. Basically a copy and paste from
cmd_for_window however it has → handling and injects a `move container to
workspace`
This commit is contained in:
crondog 2016-01-15 16:03:34 +11:00
parent 0ba3f08f52
commit 81caf89ff8

View file

@ -34,6 +34,7 @@ struct cmd_handler {
sway_cmd *handle; sway_cmd *handle;
}; };
static sway_cmd cmd_assign;
static sway_cmd cmd_bar; static sway_cmd cmd_bar;
static sway_cmd cmd_bindcode; static sway_cmd cmd_bindcode;
static sway_cmd cmd_bindsym; static sway_cmd cmd_bindsym;
@ -154,6 +155,47 @@ static struct cmd_results *checkarg(int argc, const char *name, enum expected_ar
return error; return error;
} }
static struct cmd_results *cmd_assign(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "assign", EXPECTED_AT_LEAST, 2))) {
return error;
}
char *criteria = *argv++;
if (strncmp(*argv, "", 1) == 0) {
argv++;
}
char *movecmd = "move container to workspace ";
int arglen = strlen(*argv);
char *cmdlist = calloc(1, sizeof(movecmd) + arglen);
sprintf(cmdlist, "%s%s", movecmd, *argv);
struct criteria *crit = malloc(sizeof(struct criteria));
crit->crit_raw = strdup(criteria);
crit->cmdlist = cmdlist;
crit->tokens = create_list();
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
if (err_str) {
error = cmd_results_new(CMD_INVALID, "assign", err_str);
free(err_str);
free_criteria(crit);
} else if (crit->tokens->length == 0) {
error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria");
free_criteria(crit);
} else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
sway_log(L_DEBUG, "assign: Duplicate, skipping.");
free_criteria(crit);
} else {
sway_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
list_add(config->criteria, crit);
}
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
int binding_order = 0; int binding_order = 0;
static struct cmd_results *cmd_bindsym(int argc, char **argv) { static struct cmd_results *cmd_bindsym(int argc, char **argv) {
@ -1625,6 +1667,7 @@ static struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) {
/* Keep alphabetized */ /* Keep alphabetized */
static struct cmd_handler handlers[] = { static struct cmd_handler handlers[] = {
{ "assign", cmd_assign },
{ "bar", cmd_bar }, { "bar", cmd_bar },
{ "bindcode", cmd_bindcode }, { "bindcode", cmd_bindcode },
{ "bindsym", cmd_bindsym }, { "bindsym", cmd_bindsym },