- if (num < 1)
- return false;
-
- coordinates_t ref = {mon, mon->desk, mon->desk->focus};
- coordinates_t trg = ref;
-
- if (*args[0] != OPT_CHR) {
- if (node_from_desc(*args, &ref, &trg))
- num--, args++;
- else
- return false;
- }
-
- if (trg.node == NULL)
- return false;
-
- bool dirty = false;
-
- while (num > 0) {
- if (streq("-f", *args) || streq("--focus", *args)) {
- coordinates_t dst = trg;
- if (num > 1 && *(args + 1)[0] != OPT_CHR) {
- num--, args++;
- if (!node_from_desc(*args, &trg, &dst))
- return false;
- }
- focus_node(dst.monitor, dst.desktop, dst.node);
- } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
- num--, args++;
- coordinates_t dst;
- if (desktop_from_desc(*args, &trg, &dst)) {
- if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
- trg.monitor = dst.monitor;
- trg.desktop = dst.desktop;
- }
- } else {
- return false;
- }
- } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
- num--, args++;
- if (num < 1)
- return false;
- coordinates_t dst;
- if (monitor_from_desc(*args, &trg, &dst)) {
- if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
- trg.monitor = dst.monitor;
- trg.desktop = dst.monitor->desk;
- }
- } else {
- return false;
- }
- } else if (streq("-w", *args) || streq("--to-window", *args)) {
- num--, args++;
- if (num < 1)
- return false;
- coordinates_t dst;
- if (node_from_desc(*args, &trg, &dst)) {
- if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
- trg.monitor = dst.monitor;
- trg.desktop = dst.desktop;
- }
- } else {
- return false;
- }
- } else if (streq("-s", *args) || streq("--swap", *args)) {
- num--, args++;
- if (num < 1)
- return false;
- coordinates_t dst;
- if (node_from_desc(*args, &trg, &dst)) {
- if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
- if (trg.desktop != dst.desktop)
- arrange(trg.monitor, trg.desktop);
- trg.monitor = dst.monitor;
- trg.desktop = dst.desktop;
- dirty = true;
- }
- } else {
- return false;
- }
- } else if (streq("-t", *args) || streq("--toggle", *args)) {
- num--, args++;
- if (num < 1)
- return false;
- char *key = strtok(*args, EQL_TOK);
- char *val = strtok(NULL, EQL_TOK);
- alter_state_t a;
- bool b;
- if (val == NULL) {
- a = ALTER_TOGGLE;
- } else {
- if (parse_bool(val, &b))
- a = ALTER_SET;
- else
- return false;
- }
- if (streq("fullscreen", key)) {
- set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
- dirty = true;
- } else if (streq("floating", key)) {
- set_floating(trg.node, (a == ALTER_SET ? b : !trg.node->client->floating));
- dirty = true;
- } else if (streq("locked", key)) {
- set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
- } else if (streq("sticky", key)) {
- set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
- } else if (streq("private", key)) {
- set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
- } else {
- return false;
- }
- } else if (streq("-p", *args) || streq("--presel", *args)) {
- num--, args++;
- if (num < 1 || !is_tiled(trg.node->client)
- || trg.desktop->layout != LAYOUT_TILED)
- return false;
- if (streq("cancel", *args)) {
- reset_mode(&trg);
- } else {
- direction_t dir;
- if (parse_direction(*args, &dir)) {
- double rat = trg.node->split_ratio;
- if (num > 1 && *(args + 1)[0] != OPT_CHR) {
- num--, args++;
- if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
- return false;
- }
- if (auto_cancel && trg.node->split_mode == MODE_MANUAL
- && dir == trg.node->split_dir
- && rat == trg.node->split_ratio) {
- reset_mode(&trg);
- } else {
- trg.node->split_mode = MODE_MANUAL;
- trg.node->split_dir = dir;
- trg.node->split_ratio = rat;
- }
- window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
- } else {
- return false;
- }
- }
- } else if (streq("-e", *args) || streq("--edge", *args)) {
- num--, args++;
- if (num < 2)
- return false;
- direction_t dir;
- if (!parse_direction(*args, &dir))
- return false;
- node_t *n = find_fence(trg.node, dir);
- if (n == NULL)
- return false;
- num--, args++;
- fence_move_t fmo;
- if (parse_fence_move(*args, &fmo)) {
- move_fence(n, dir, fmo);
- } else {
- double rat;
- if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
- n->split_ratio = rat;
- else
- return false;
- }
- dirty = true;
- } else if (streq("-r", *args) || streq("--ratio", *args)) {
- num--, args++;
- if (num < 1)
- return false;
- double rat;
- if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
- trg.node->split_ratio = rat;
- window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
- } else {
- return false;
- }
- } else if (streq("-R", *args) || streq("--rotate", *args)) {
- num--, args++;
- if (num < 2)
- return false;
- direction_t dir;
- if (!parse_direction(*args, &dir))
- return false;
- node_t *n = find_fence(trg.node, dir);
- if (n == NULL)
- return false;
- num--, args++;
- int deg;
- if (parse_degree(*args, °)) {
- rotate_tree(n, deg);
- dirty = true;
- } else {
- return false;
- }
- } else if (streq("-c", *args) || streq("--close", *args)) {
- if (num > 1)
- return false;
- window_close(trg.node);
- } else if (streq("-k", *args) || streq("--kill", *args)) {
- if (num > 1)
- return false;
- window_kill(trg.monitor, trg.desktop, trg.node);
- dirty = true;
- } else {
- return false;
- }
-
- num--, args++;
- }
-
- if (dirty)
- arrange(trg.monitor, trg.desktop);
-
- return true;
+ if (num < 1)
+ return MSG_SYNTAX;
+
+ coordinates_t ref = {mon, mon->desk, mon->desk->focus};
+ coordinates_t trg = ref;
+
+ if ((*args)[0] != OPT_CHR) {
+ if (node_from_desc(*args, &ref, &trg))
+ num--, args++;
+ else
+ return MSG_FAILURE;
+ }
+
+ if (trg.node == NULL)
+ return MSG_FAILURE;
+
+ bool dirty = false;
+
+ while (num > 0) {
+ if (streq("-f", *args) || streq("--focus", *args)) {
+ coordinates_t dst = trg;
+ if (num > 1 && *(args + 1)[0] != OPT_CHR) {
+ num--, args++;
+ if (!node_from_desc(*args, &trg, &dst))
+ return MSG_FAILURE;
+ }
+ focus_node(dst.monitor, dst.desktop, dst.node);
+ } else if (streq("-a", *args) || streq("--activate", *args)) {
+ coordinates_t dst = trg;
+ if (num > 1 && *(args + 1)[0] != OPT_CHR) {
+ num--, args++;
+ if (!node_from_desc(*args, &trg, &dst))
+ return MSG_FAILURE;
+ }
+ if (dst.desktop == mon->desk) {
+ return MSG_FAILURE;
+ }
+ activate_node(dst.monitor, dst.desktop, dst.node);
+ } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
+ num--, args++;
+ coordinates_t dst;
+ if (desktop_from_desc(*args, &trg, &dst)) {
+ if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
+ trg.monitor = dst.monitor;
+ trg.desktop = dst.desktop;
+ }
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ coordinates_t dst;
+ if (monitor_from_desc(*args, &trg, &dst)) {
+ if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
+ trg.monitor = dst.monitor;
+ trg.desktop = dst.monitor->desk;
+ }
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-w", *args) || streq("--to-window", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ coordinates_t dst;
+ if (node_from_desc(*args, &trg, &dst)) {
+ if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
+ trg.monitor = dst.monitor;
+ trg.desktop = dst.desktop;
+ }
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-s", *args) || streq("--swap", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ coordinates_t dst;
+ if (node_from_desc(*args, &trg, &dst)) {
+ if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
+ if (trg.desktop != dst.desktop)
+ arrange(trg.monitor, trg.desktop);
+ trg.monitor = dst.monitor;
+ trg.desktop = dst.desktop;
+ dirty = true;
+ }
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-t", *args) || streq("--state", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ client_state_t cst;
+ if (parse_client_state(*args, &cst)) {
+ set_state(trg.monitor, trg.desktop, trg.node, cst);
+ dirty = true;
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-g", *args) || streq("--flag", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ char *key = strtok(*args, EQL_TOK);
+ char *val = strtok(NULL, EQL_TOK);
+ alter_state_t a;
+ bool b;
+ if (val == NULL) {
+ a = ALTER_TOGGLE;
+ } else {
+ if (parse_bool(val, &b)) {
+ a = ALTER_SET;
+ } else {
+ return MSG_FAILURE;
+ }
+ }
+ if (streq("locked", key)) {
+ set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
+ } else if (streq("sticky", key)) {
+ set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
+ } else if (streq("private", key)) {
+ set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-p", *args) || streq("--presel", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ if (IS_FLOATING(trg.node->client) ||
+ trg.desktop->layout != LAYOUT_TILED)
+ return MSG_FAILURE;
+ if (streq("cancel", *args)) {
+ reset_mode(&trg);
+ } else {
+ direction_t dir;
+ if (parse_direction(*args, &dir)) {
+ double rat = trg.node->split_ratio;
+ if (num > 1 && *(args + 1)[0] != OPT_CHR) {
+ num--, args++;
+ if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
+ return MSG_FAILURE;
+ }
+ if (auto_cancel && trg.node->split_mode == MODE_MANUAL &&
+ dir == trg.node->split_dir &&
+ rat == trg.node->split_ratio) {
+ reset_mode(&trg);
+ } else {
+ trg.node->split_mode = MODE_MANUAL;
+ trg.node->split_dir = dir;
+ trg.node->split_ratio = rat;
+ }
+ window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
+ } else {
+ return MSG_FAILURE;
+ }
+ }
+ } else if (streq("-e", *args) || streq("--edge", *args)) {
+ num--, args++;
+ if (num < 2)
+ return MSG_SYNTAX;
+ if (IS_FLOATING(trg.node->client))
+ return MSG_FAILURE;
+ direction_t dir;
+ if (!parse_direction(*args, &dir))
+ return MSG_FAILURE;
+ node_t *n = find_fence(trg.node, dir);
+ if (n == NULL)
+ return MSG_FAILURE;
+ num--, args++;
+ if ((*args)[0] == '+' || (*args)[0] == '-') {
+ int pix;
+ if (sscanf(*args, "%i", &pix) == 1) {
+ int max = (n->split_type == TYPE_HORIZONTAL ? n->rectangle.height : n->rectangle.width);
+ double rat = ((max * n->split_ratio) + pix) / max;
+ if (rat > 0 && rat < 1)
+ n->split_ratio = rat;
+ else
+ return MSG_FAILURE;
+ } else {
+ return MSG_FAILURE;
+ }
+ } else {
+ double rat;
+ if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
+ n->split_ratio = rat;
+ else
+ return MSG_FAILURE;
+ }
+ dirty = true;
+ } else if (streq("-r", *args) || streq("--ratio", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ double rat;
+ if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
+ trg.node->split_ratio = rat;
+ window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-l", *args) || streq("--layer", *args)) {
+ num--, args++;
+ if (num < 1) {
+ return MSG_SYNTAX;
+ }
+ stack_layer_t lyr;
+ if (parse_stack_layer(*args, &lyr)) {
+ set_layer(trg.monitor, trg.desktop, trg.node, lyr);
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-R", *args) || streq("--rotate", *args)) {
+ num--, args++;
+ if (num < 2)
+ return MSG_SYNTAX;
+ direction_t dir;
+ if (!parse_direction(*args, &dir))
+ return MSG_FAILURE;
+ node_t *n = find_fence(trg.node, dir);
+ if (n == NULL)
+ return MSG_FAILURE;
+ num--, args++;
+ int deg;
+ if (parse_degree(*args, °)) {
+ rotate_tree(n, deg);
+ dirty = true;
+ } else {
+ return MSG_FAILURE;
+ }
+ } else if (streq("-c", *args) || streq("--close", *args)) {
+ if (num > 1)
+ return MSG_SYNTAX;
+ window_close(trg.node);
+ } else if (streq("-k", *args) || streq("--kill", *args)) {
+ if (num > 1)
+ return MSG_SYNTAX;
+ window_kill(trg.monitor, trg.desktop, trg.node);
+ dirty = true;
+ } else {
+ return MSG_SYNTAX;
+ }
+
+ num--, args++;
+ }
+
+ if (dirty)
+ arrange(trg.monitor, trg.desktop);
+
+ return MSG_SUCCESS;