2018-04-24 06:59:49 +02:00
|
|
|
#define _XOPEN_SOURCE 700
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/criteria.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
2018-05-09 06:23:20 +02:00
|
|
|
#include "stringop.h"
|
2018-04-24 06:59:49 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:23:20 +02:00
|
|
|
// Create criteria
|
|
|
|
char *err_str = NULL;
|
|
|
|
struct criteria *criteria = criteria_parse(argv[0], &err_str);
|
|
|
|
if (!criteria) {
|
|
|
|
error = cmd_results_new(CMD_INVALID, "assign", err_str);
|
|
|
|
free(err_str);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
++argv;
|
|
|
|
int target_len = argc - 1;
|
2018-04-24 06:59:49 +02:00
|
|
|
|
|
|
|
if (strncmp(*argv, "→", strlen("→")) == 0) {
|
|
|
|
if (argc < 3) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
|
|
|
|
}
|
2018-05-09 06:23:20 +02:00
|
|
|
++argv;
|
|
|
|
--target_len;
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 06:23:20 +02:00
|
|
|
if (strcmp(*argv, "output") == 0) {
|
|
|
|
criteria->type = CT_ASSIGN_OUTPUT;
|
|
|
|
++argv;
|
|
|
|
--target_len;
|
|
|
|
} else {
|
|
|
|
criteria->type = CT_ASSIGN_WORKSPACE;
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 06:23:20 +02:00
|
|
|
criteria->target = join_args(argv, target_len);
|
2018-04-24 06:59:49 +02:00
|
|
|
|
2018-05-09 06:23:20 +02:00
|
|
|
list_add(config->criteria, criteria);
|
|
|
|
wlr_log(L_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
|
|
|
|
criteria->target);
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|