- char *cmd = strtok(msg, TOK_SEP);
-
- if (cmd == NULL)
- return;
-
- if (strcmp(cmd, "get") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- get_setting(name, rsp);
- return;
- } else if (strcmp(cmd, "set") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- char *value = strtok(NULL, TOK_SEP);
- set_setting(name, value, rsp);
- return;
- } else if (strcmp(cmd, "list") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- desktop_location_t loc;
- if (locate_desktop(name, &loc))
- list(loc.desktop, loc.desktop->root, rsp, 0);
- } else {
- list(mon->desk, mon->desk->root, rsp, 0);
- }
- return;
- } else if (strcmp(cmd, "list_monitors") == 0) {
- char *arg = strtok(NULL, TOK_SEP);
- list_option_t opt;
- if (parse_list_option(arg, &opt))
- list_monitors(opt, rsp);
- return;
- } else if (strcmp(cmd, "list_desktops") == 0) {
- char *arg = strtok(NULL, TOK_SEP);
- list_option_t opt;
- if (parse_list_option(arg, &opt))
- list_desktops(mon, opt, 0, rsp);
- return;
- } else if (strcmp(cmd, "list_windows") == 0) {
- list_windows(rsp);
- return;
- } else if (strcmp(cmd, "list_history") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- desktop_location_t loc;
- if (locate_desktop(name, &loc))
- list_history(loc.desktop, rsp);
- } else {
- list_history(mon->desk, rsp);
- }
- return;
- } else if (strcmp(cmd, "list_rules") == 0) {
- list_rules(rsp);
- return;
- } else if (strcmp(cmd, "close") == 0) {
- window_close(mon->desk->focus);
- return;
- } else if (strcmp(cmd, "kill") == 0) {
- window_kill(mon->desk, mon->desk->focus);
- } else if (strcmp(cmd, "rotate") == 0) {
- char *deg = strtok(NULL, TOK_SEP);
- if (deg != NULL) {
- rotate_t r;
- if (parse_rotate(deg, &r))
- rotate_tree(mon->desk->root, r);
- }
- } else if (strcmp(cmd, "flip") == 0) {
- char *flp = strtok(NULL, TOK_SEP);
- if (flp != NULL) {
- flip_t f;
- if (parse_flip(flp, &f))
- flip_tree(mon->desk->root, f);
- }
- } else if (strcmp(cmd, "grab_pointer") == 0) {
- char *pac = strtok(NULL, TOK_SEP);
- if (pac != NULL) {
- pointer_action_t a;
- if (parse_pointer_action(pac, &a))
- grab_pointer(a);
- }
- } else if (strcmp(cmd, "track_pointer") == 0) {
- char *arg1 = strtok(NULL, TOK_SEP);
- if (arg1 == NULL)
- return;
- char *arg2 = strtok(NULL, TOK_SEP);
- if (arg2 == NULL)
- return;
- int root_x, root_y;
- if (sscanf(arg1, "%i", &root_x) == 1 && sscanf(arg2, "%i", &root_y) == 1)
- track_pointer(root_x, root_y);
- return;
- } else if (strcmp(cmd, "ungrab_pointer") == 0) {
- ungrab_pointer();
- } else if (strcmp(cmd, "layout") == 0) {
- char *lyt = strtok(NULL, TOK_SEP);
- if (lyt != NULL) {
- layout_t y;
- if (parse_layout(lyt, &y)) {
- char *name = strtok(NULL, TOK_SEP);
- if (name == NULL) {
- mon->desk->layout = y;
- } else {
- desktop_location_t loc;
- do {
- if (locate_desktop(name, &loc))
- loc.desktop->layout = y;
- } while ((name = strtok(NULL, TOK_SEP)) != NULL);
- }
- }
- }
- put_status();
- } else if (strcmp(cmd, "cycle_layout") == 0) {
- if (mon->desk->layout == LAYOUT_MONOCLE)
- mon->desk->layout = LAYOUT_TILED;
- else
- mon->desk->layout = LAYOUT_MONOCLE;
- put_status();
- } else if (strcmp(cmd, "shift") == 0) {
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- direction_t d;
- if (parse_direction(dir, &d)) {
- swap_nodes(mon->desk->focus, find_neighbor(mon->desk->focus, d));
- }
- }
- } else if (strcmp(cmd, "toggle_fullscreen") == 0) {
- if (mon->desk->focus != NULL)
- toggle_fullscreen(mon, mon->desk->focus->client);
- } else if (strcmp(cmd, "toggle_floating") == 0) {
- split_mode = MODE_AUTOMATIC;
- toggle_floating(mon->desk->focus);
- } else if (strcmp(cmd, "toggle_locked") == 0) {
- if (mon->desk->focus != NULL)
- toggle_locked(mon->desk->focus->client);
- } else if (strcmp(cmd, "toggle_visibility") == 0) {
- toggle_visibility();
- } else if (strcmp(cmd, "pad") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- monitor_t *m = find_monitor(name);
- if (m != NULL) {
- char args[BUFSIZ] = {0}, *s;
- while ((s = strtok(NULL, TOK_SEP)) != NULL) {
- strncat(args, s, REMLEN(args));
- strncat(args, TOK_SEP, REMLEN(args));
- }
- if (strlen(args) > 0) {
- sscanf(args, "%i %i %i %i", &m->top_padding, &m->right_padding, &m->bottom_padding, &m->left_padding);
- arrange(m, m->desk);
- } else {
- snprintf(rsp, BUFSIZ, "%i %i %i %i\n", m->top_padding, m->right_padding, m->bottom_padding, m->left_padding);
- }
- }
- }
- return;
- } else if (strcmp(cmd, "ratio") == 0) {
- char *value = strtok(NULL, TOK_SEP);
- if (value != NULL && mon->desk->focus != NULL)
- sscanf(value, "%lf", &mon->desk->focus->split_ratio);
- } else if (strcmp(cmd, "cancel") == 0) {
- split_mode = MODE_AUTOMATIC;
- window_draw_border(mon->desk->focus, true, true);
- return;
- } else if (strcmp(cmd, "presel") == 0) {
- if (mon->desk->focus == NULL || !is_tiled(mon->desk->focus->client) || mon->desk->layout != LAYOUT_TILED)
- return;
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- direction_t d;
- if (parse_direction(dir, &d)) {
- split_mode = MODE_MANUAL;
- split_dir = d;
- char *rat = strtok(NULL, TOK_SEP);
- if (rat != NULL)
- sscanf(rat, "%lf", &mon->desk->focus->split_ratio);
- window_draw_border(mon->desk->focus, true, true);
- }
- }
- return;
- } else if (strcmp(cmd, "push") == 0 || strcmp(cmd, "pull") == 0) {
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- fence_move_t m;
- direction_t d;
- if (parse_fence_move(cmd, &m) && parse_direction(dir, &d)) {
- move_fence(mon->desk->focus, d, m);
- }
- }
- } else if (strcmp(cmd, "drop_to_monitor") == 0) {
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- cycle_dir_t d;
- if (parse_cycle_direction(dir, &d)) {
- monitor_t *m;
- if (d == CYCLE_NEXT)
- m = ((mon->next == NULL ? mon_head : mon->next));
- else
- m = ((mon->prev == NULL ? mon_tail : mon->prev));
- transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
- arrange(m, m->desk);
- char *opt = strtok(NULL, TOK_SEP);
- send_option_t o;
- if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
- select_monitor(m);
- }
- }
- } else if (strcmp(cmd, "send_to_monitor") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- monitor_t *m = find_monitor(name);
- if (m != NULL && m != mon) {
- transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
- arrange(m, m->desk);
- char *opt = strtok(NULL, TOK_SEP);
- send_option_t o;
- if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
- select_monitor(m);
- }
- }
- } else if (strcmp(cmd, "drop_to") == 0) {
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- cycle_dir_t c;
- if (parse_cycle_direction(dir, &c)) {
- desktop_t *d;
- if (c == CYCLE_NEXT)
- d = ((mon->desk->next == NULL ? mon->desk_head : mon->desk->next));
- else
- d = ((mon->desk->prev == NULL ? mon->desk_tail : mon->desk->prev));
- transfer_node(mon, mon->desk, mon, d, mon->desk->focus);
- char *opt = strtok(NULL, TOK_SEP);
- send_option_t o;
- if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
- select_desktop(d);
- }
- }
- } else if (strcmp(cmd, "send_to") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- desktop_location_t loc;
- if (locate_desktop(name, &loc)) {
- transfer_node(mon, mon->desk, loc.monitor, loc.desktop, mon->desk->focus);
- if (mon != loc.monitor && loc.monitor->desk == loc.desktop)
- arrange(loc.monitor, loc.desktop);
- char *opt = strtok(NULL, TOK_SEP);
- send_option_t o;
- if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW) {
- select_monitor(loc.monitor);
- select_desktop(loc.desktop);
- }
- }
- }
- } else if (strcmp(cmd, "rename_monitor") == 0) {
- char *cur_name = strtok(NULL, TOK_SEP);
- if (cur_name != NULL) {
- monitor_t *m = find_monitor(cur_name);
- if (m != NULL) {
- char *new_name = strtok(NULL, TOK_SEP);
- if (new_name != NULL) {
- strncpy(m->name, new_name, sizeof(m->name));
- put_status();
- }
- }
- }
- } else if (strcmp(cmd, "rename") == 0) {
- char *cur_name = strtok(NULL, TOK_SEP);
- if (cur_name != NULL) {
- desktop_location_t loc;
- if (locate_desktop(cur_name, &loc)) {
- char *new_name = strtok(NULL, TOK_SEP);
- if (new_name != NULL) {
- strncpy(loc.desktop->name, new_name, sizeof(loc.desktop->name));
- ewmh_update_desktop_names();
- put_status();
- }
- }
- }
- } else if (strcmp(cmd, "use_monitor") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- monitor_t *m = find_monitor(name);
- if (m != NULL)
- select_monitor(m);
- }
- } else if (strcmp(cmd, "use") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- desktop_location_t loc;
- if (locate_desktop(name, &loc)) {
- if (loc.desktop == mon->desk) {
- select_desktop(mon->last_desk);
- } else {
- select_monitor(loc.monitor);
- select_desktop(loc.desktop);
- }
- }
- }
- } else if (strcmp(cmd, "cycle_monitor") == 0) {
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- cycle_dir_t d;
- if (parse_cycle_direction(dir, &d))
- cycle_monitor(d);
- }
- } else if (strcmp(cmd, "cycle_desktop") == 0) {
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- cycle_dir_t d;
- if (parse_cycle_direction(dir, &d)) {
- skip_desktop_t k;
- char *skip = strtok(NULL, TOK_SEP);
- if (parse_skip_desktop(skip, &k))
- cycle_desktop(mon, mon->desk, d, k);
- }
- }
- } else if (strcmp(cmd, "cycle") == 0) {
- if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
- return;
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- cycle_dir_t d;
- if (parse_cycle_direction(dir, &d)) {
- skip_client_t k;
- char *skip = strtok(NULL, TOK_SEP);
- if (parse_skip_client(skip, &k))
- cycle_leaf(mon, mon->desk, mon->desk->focus, d, k);
- }
- }
- return;
- } else if (strcmp(cmd, "nearest") == 0) {
- if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
- return;
- char *arg = strtok(NULL, TOK_SEP);
- if (arg != NULL) {
- nearest_arg_t a;
- if (parse_nearest_argument(arg, &a)) {
- skip_client_t k;
- char *skip = strtok(NULL, TOK_SEP);
- if (parse_skip_client(skip, &k))
- nearest_leaf(mon, mon->desk, mon->desk->focus, a, k);
- }
- }
- return;
- } else if (strcmp(cmd, "circulate") == 0) {
- if (mon->desk->layout == LAYOUT_MONOCLE
- || (mon->desk->focus != NULL && !is_tiled(mon->desk->focus->client)))
- return;
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- circulate_dir_t d;
- if (parse_circulate_direction(dir, &d))
- circulate_leaves(mon, mon->desk, d);
- }
- } else if (strcmp(cmd, "rule") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- rule_t *rule = make_rule();
- strncpy(rule->cause.name, name, sizeof(rule->cause.name));
- char *arg = strtok(NULL, TOK_SEP);
- while (arg != NULL) {
- if (strcmp(arg, "floating") == 0) {
- rule->effect.floating = true;
- } else {
- desktop_location_t loc;
- if (locate_desktop(arg, &loc)) {
- rule->effect.monitor = loc.monitor;
- rule->effect.desktop = loc.desktop;
- }
- }
- arg = strtok(NULL, TOK_SEP);
- }
- add_rule(rule);
- }
- return;
- } else if (strcmp(cmd, "remove_rule") == 0) {
- char *arg;
- unsigned int uid;
- while ((arg = strtok(NULL, TOK_SEP)) != NULL)
- if (sscanf(arg, "%X", &uid) > 0)
- remove_rule_by_uid(uid);
- return;
- } else if (strcmp(cmd, "swap") == 0) {
- swap_nodes(mon->desk->focus, history_get(mon->desk->history, 1));
- } else if (strcmp(cmd, "alternate") == 0) {
- focus_node(mon, mon->desk, history_get(mon->desk->history, 1), true);
- return;
- } else if (strcmp(cmd, "alternate_desktop") == 0) {
- select_desktop(mon->last_desk);
- } else if (strcmp(cmd, "alternate_monitor") == 0) {
- select_monitor(last_mon);
- } else if (strcmp(cmd, "add_in") == 0) {
- char *name = strtok(NULL, TOK_SEP);
- if (name != NULL) {
- monitor_t *m = find_monitor(name);
- if (m != NULL)
- for (name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP))
- add_desktop(m, name);
- }
- return;
- } else if (strcmp(cmd, "add") == 0) {
- for (char *name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP))
- add_desktop(mon, name);
- return;
- } else if (strcmp(cmd, "focus") == 0) {
- if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
- return;
- char *dir = strtok(NULL, TOK_SEP);
- if (dir != NULL) {
- direction_t d;
- if (parse_direction(dir, &d)) {
- node_t *n = find_neighbor(mon->desk->focus, d);
- focus_node(mon, mon->desk, n, true);
- }
- }
- if (mon->desk->layout == LAYOUT_TILED)
- return;
- } else if (strcmp(cmd, "adopt_orphans") == 0) {
- adopt_orphans();
- } else if (strcmp(cmd, "reload_autostart") == 0) {
- run_autostart();
- } else if (strcmp(cmd, "reload_settings") == 0) {
- load_settings();
- } else if (strcmp(cmd, "restore") == 0) {
- char *arg = strtok(NULL, TOK_SEP);
- restore(arg);
- } else if (strcmp(cmd, "quit") == 0) {
- char *arg = strtok(NULL, TOK_SEP);
- if (arg != NULL)
- sscanf(arg, "%i", &exit_status);
- quit();
- return;
- } else {
- snprintf(rsp, BUFSIZ, "unknown command: %s", cmd);
- return;
- }
-
- arrange(mon, mon->desk);