#include "settings.h"
#include "tree.h"
#include "window.h"
+#include "common.h"
+#include "subscribe.h"
#include "messages.h"
-bool handle_message(char *msg, int msg_len, char *rsp)
+int handle_message(char *msg, int msg_len, FILE *rsp)
{
int cap = INIT_CAP;
int num = 0;
char **args = malloc(cap * sizeof(char *));
if (args == NULL)
- return false;
+ return MSG_FAILURE;
for (int i = 0, j = 0; i < msg_len; i++) {
if (msg[i] == 0) {
char **new = realloc(args, cap * sizeof(char *));
if (new == NULL) {
free(args);
- return false;
+ return MSG_FAILURE;
} else {
args = new;
}
if (num < 1) {
free(args);
- return false;
+ return MSG_SYNTAX;
}
char **args_orig = args;
- bool ret = process_message(args, num, rsp);
+ int ret = process_message(args, num, rsp);
free(args_orig);
return ret;
}
-bool process_message(char **args, int num, char *rsp)
+int process_message(char **args, int num, FILE *rsp)
{
if (streq("window", *args)) {
return cmd_window(++args, --num);
return cmd_quit(++args, --num);
}
- return false;
+ return MSG_UNKNOWN;
}
-bool cmd_window(char **args, int num)
+int cmd_window(char **args, int num)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = ref;
if (node_from_desc(*args, &ref, &trg))
num--, args++;
else
- return false;
+ return MSG_FAILURE;
}
if (trg.node == NULL)
- return false;
+ return MSG_FAILURE;
bool dirty = false;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!node_from_desc(*args, &trg, &dst))
- return false;
+ return MSG_FAILURE;
}
focus_node(dst.monitor, dst.desktop, dst.node);
} else if (streq("-d", *args) || streq("--to-desktop", *args)) {
trg.desktop = dst.desktop;
}
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-m", *args) || streq("--to-monitor", *args)) {
num--, args++;
if (num < 1)
- return false;
+ 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.desktop = dst.monitor->desk;
}
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-w", *args) || streq("--to-window", *args)) {
num--, args++;
if (num < 1)
- return false;
+ 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.desktop = dst.desktop;
}
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
if (num < 1)
- return false;
+ 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)) {
dirty = true;
}
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-t", *args) || streq("--toggle", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
char *key = strtok(*args, EQL_TOK);
char *val = strtok(NULL, EQL_TOK);
alter_state_t a;
if (parse_bool(val, &b))
a = ALTER_SET;
else
- return false;
+ return MSG_FAILURE;
}
if (streq("fullscreen", key)) {
set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
} else if (streq("private", key)) {
set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
} else {
- return false;
+ return MSG_FAILURE;
}
} 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 (num < 1)
+ return MSG_SYNTAX;
+ if (!is_tiled(trg.node->client) ||
+ trg.desktop->layout != LAYOUT_TILED)
+ return MSG_FAILURE;
if (streq("cancel", *args)) {
reset_mode(&trg);
} else {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
- return false;
+ return MSG_FAILURE;
}
if (auto_cancel && trg.node->split_mode == MODE_MANUAL &&
dir == trg.node->split_dir &&
}
window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
} else {
- return false;
+ return MSG_FAILURE;
}
}
} else if (streq("-e", *args) || streq("--edge", *args)) {
num--, args++;
if (num < 2)
- return false;
+ return MSG_SYNTAX;
direction_t dir;
if (!parse_direction(*args, &dir))
- return false;
+ return MSG_FAILURE;
node_t *n = find_fence(trg.node, dir);
if (n == NULL)
- return false;
+ return MSG_FAILURE;
num--, args++;
if ((*args)[0] == '+' || (*args)[0] == '-') {
int pix;
if (rat > 0 && rat < 1)
n->split_ratio = rat;
else
- return false;
+ return MSG_FAILURE;
} else {
- return false;
+ return MSG_FAILURE;
}
} else {
double rat;
if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
n->split_ratio = rat;
else
- return false;
+ return MSG_FAILURE;
}
dirty = true;
} else if (streq("-r", *args) || streq("--ratio", *args)) {
num--, args++;
if (num < 1)
- return false;
+ 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 false;
+ return MSG_FAILURE;
}
} else if (streq("-R", *args) || streq("--rotate", *args)) {
num--, args++;
if (num < 2)
- return false;
+ return MSG_SYNTAX;
direction_t dir;
if (!parse_direction(*args, &dir))
- return false;
+ return MSG_FAILURE;
node_t *n = find_fence(trg.node, dir);
if (n == NULL)
- return false;
+ return MSG_FAILURE;
num--, args++;
int deg;
if (parse_degree(*args, °)) {
rotate_tree(n, deg);
dirty = true;
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-c", *args) || streq("--close", *args)) {
if (num > 1)
- return false;
+ return MSG_SYNTAX;
window_close(trg.node);
} else if (streq("-k", *args) || streq("--kill", *args)) {
if (num > 1)
- return false;
+ return MSG_SYNTAX;
window_kill(trg.monitor, trg.desktop, trg.node);
dirty = true;
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
if (dirty)
arrange(trg.monitor, trg.desktop);
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_desktop(char **args, int num)
+int cmd_desktop(char **args, int num)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
coordinates_t ref = {mon, mon->desk, NULL};
coordinates_t trg = ref;
if (desktop_from_desc(*args, &ref, &trg))
num--, args++;
else
- return false;
+ return MSG_FAILURE;
}
bool dirty = false;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!desktop_from_desc(*args, &trg, &dst))
- return false;
+ return MSG_FAILURE;
}
if (auto_alternate && dst.desktop == mon->desk) {
desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
} else if (streq("-m", *args) || streq("--to-monitor", *args)) {
num--, args++;
- if (num < 1 || trg.monitor->desk_head == trg.monitor->desk_tail)
- return false;
+ if (num < 1)
+ return MSG_SYNTAX;
+ if (trg.monitor->desk_head == trg.monitor->desk_tail)
+ return MSG_FAILURE;
coordinates_t dst;
if (monitor_from_desc(*args, &trg, &dst)) {
transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
trg.monitor = dst.monitor;
update_current();
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
coordinates_t dst;
if (desktop_from_desc(*args, &trg, &dst))
swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
else
- return false;
+ return MSG_FAILURE;
} else if (streq("-l", *args) || streq("--layout", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
layout_t lyt;
cycle_dir_t cyc;
if (parse_cycle_direction(*args, &cyc))
else if (parse_layout(*args, &lyt))
change_layout(trg.monitor, trg.desktop, lyt);
else
- return false;
+ return MSG_FAILURE;
} else if (streq("-n", *args) || streq("--rename", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
ewmh_update_desktop_names();
put_status();
remove_desktop(trg.monitor, trg.desktop);
show_desktop(trg.monitor->desk);
update_current();
- return true;
+ return MSG_SUCCESS;
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
reset_mode(&trg);
} else if (streq("-F", *args) || streq("--flip", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
flip_t flp;
if (parse_flip(*args, &flp)) {
flip_tree(trg.desktop->root, flp);
dirty = true;
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-R", *args) || streq("--rotate", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
int deg;
if (parse_degree(*args, °)) {
rotate_tree(trg.desktop->root, deg);
dirty = true;
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-E", *args) || streq("--equalize", *args)) {
equalize_tree(trg.desktop->root);
} else if (streq("-C", *args) || streq("--circulate", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
circulate_dir_t cir;
if (parse_circulate_direction(*args, &cir)) {
circulate_leaves(trg.monitor, trg.desktop, cir);
dirty = true;
} else {
- return false;
+ return MSG_FAILURE;
}
} else if (streq("-t", *args) || streq("--toggle", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
char *key = strtok(*args, EQL_TOK);
char *val = strtok(NULL, EQL_TOK);
alter_state_t a;
if (parse_bool(val, &b))
a = ALTER_SET;
else
- return false;
+ return MSG_FAILURE;
}
if (streq("floating", key))
trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
else
- return false;
+ return MSG_FAILURE;
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
if (dirty)
arrange(trg.monitor, trg.desktop);
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_monitor(char **args, int num)
+int cmd_monitor(char **args, int num)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
coordinates_t ref = {mon, NULL, NULL};
coordinates_t trg = ref;
if (monitor_from_desc(*args, &ref, &trg))
num--, args++;
else
- return false;
+ return MSG_FAILURE;
}
while (num > 0) {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!monitor_from_desc(*args, &trg, &dst))
- return false;
+ return MSG_FAILURE;
}
if (auto_alternate && dst.monitor == mon) {
desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
} else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
desktop_t *d = trg.monitor->desk_head;
while (num > 0 && d != NULL) {
snprintf(d->name, sizeof(d->name), "%s", *args);
} else if (streq("-a", *args) || streq("--add-desktops", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
while (num > 0) {
add_desktop(trg.monitor, make_desktop(*args));
num--, args++;
} else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
while (num > 0) {
coordinates_t dst;
if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
} else if (streq("-o", *args) || streq("--order-desktops", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
desktop_t *d = trg.monitor->desk_head;
while (d != NULL && num > 0) {
desktop_t *next = d->next;
} else if (streq("-n", *args) || streq("--rename", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
put_status();
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
coordinates_t dst;
if (monitor_from_desc(*args, &trg, &dst))
swap_monitors(trg.monitor, dst.monitor);
else
- return false;
+ return MSG_FAILURE;
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_query(char **args, int num, char *rsp)
+int cmd_query(char **args, int num, FILE *rsp)
{
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = {NULL, NULL, NULL};
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!monitor_from_desc(*args, &ref, &trg))
- return false;
+ return MSG_FAILURE;
}
t++;
} else if (streq("-d", *args) || streq("--desktop", *args)) {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!desktop_from_desc(*args, &ref, &trg))
- return false;
+ return MSG_FAILURE;
}
t++;
} else if (streq("-w", *args) || streq("--window", *args)) {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!node_from_desc(*args, &ref, &trg))
- return false;
+ return MSG_FAILURE;
}
t++;
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
if (d != 1 || t > 1)
- return false;
+ return MSG_SYNTAX;
if (dom == DOMAIN_HISTORY)
query_history(trg, rsp);
else
query_monitors(trg, dom, rsp);
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_rule(char **args, int num, char *rsp)
+int cmd_rule(char **args, int num, FILE *rsp)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
while (num > 0) {
if (streq("-a", *args) || streq("--add", *args)) {
num--, args++;
if (num < 2)
- return false;
+ return MSG_SYNTAX;
rule_t *rule = make_rule();
snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
num--, args++;
} else if (streq("-r", *args) || streq("--remove", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
int idx;
while (num > 0) {
if (parse_index(*args, &idx))
num--, args++;
list_rules(num > 0 ? *args : NULL, rsp);
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_pointer(char **args, int num)
+int cmd_pointer(char **args, int num)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
while (num > 0) {
if (streq("-t", *args) || streq("--track", *args)) {
num--, args++;
if (num < 2)
- return false;
+ return MSG_SYNTAX;
int x, y;
if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
track_pointer(x, y);
else
- return false;
+ return MSG_FAILURE;
} else if (streq("-g", *args) || streq("--grab", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
pointer_action_t pac;
if (parse_pointer_action(*args, &pac))
grab_pointer(pac);
else
- return false;
+ return MSG_FAILURE;
} else if (streq("-u", *args) || streq("--ungrab", *args)) {
ungrab_pointer();
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_restore(char **args, int num)
+int cmd_restore(char **args, int num)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
while (num > 0) {
if (streq("-T", *args) || streq("--tree", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
restore_tree(*args);
} else if (streq("-H", *args) || streq("--history", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
restore_history(*args);
} else if (streq("-S", *args) || streq("--stack", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
restore_stack(*args);
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_control(char **args, int num, char *rsp)
+int cmd_control(char **args, int num, FILE *rsp)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
while (num > 0) {
if (streq("--adopt-orphans", *args)) {
adopt_orphans();
} else if (streq("--toggle-visibility", *args)) {
toggle_visibility();
} else if (streq("--subscribe", *args)) {
- snprintf(rsp, BUFSIZ, "%c", MESSAGE_SUBSCRIBE);
+ return MSG_SUBSCRIBE;
} else if (streq("--get-status", *args)) {
- snprintf(rsp, BUFSIZ, "%c", MESSAGE_GET_STATUS);
+ print_status(rsp);
} else if (streq("--record-history", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
bool b;
if (parse_bool(*args, &b))
record_history = b;
else
- return false;
+ return MSG_SYNTAX;
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
- return true;
+ return MSG_SUCCESS;
}
-bool cmd_config(char **args, int num, char *rsp)
+int cmd_config(char **args, int num, FILE *rsp)
{
if (num < 1)
- return false;
+ return MSG_SYNTAX;
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = {NULL, NULL, NULL};
if ((*args)[0] == OPT_CHR) {
if (streq("-m", *args) || streq("--monitor", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
if (!monitor_from_desc(*args, &ref, &trg))
- return false;
+ return MSG_FAILURE;
} else if (streq("-d", *args) || streq("--desktop", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
if (!desktop_from_desc(*args, &ref, &trg))
- return false;
+ return MSG_FAILURE;
} else if (streq("-w", *args) || streq("--window", *args)) {
num--, args++;
if (num < 1)
- return false;
+ return MSG_SYNTAX;
if (!node_from_desc(*args, &ref, &trg))
- return false;
+ return MSG_FAILURE;
} else {
- return false;
+ return MSG_SYNTAX;
}
num--, args++;
}
else if (num == 1)
return get_setting(trg, *args, rsp);
else
- return false;
+ return MSG_SYNTAX;
}
-bool cmd_quit(char **args, int num)
+int cmd_quit(char **args, int num)
{
if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
- return false;
+ return MSG_FAILURE;
running = false;
- return true;
+ return MSG_SUCCESS;
}
-bool set_setting(coordinates_t loc, char *name, char *value)
+int set_setting(coordinates_t loc, char *name, char *value)
{
#define DESKWINSET(k, v) \
if (loc.node != NULL) \
if (streq("border_width", name)) {
unsigned int bw;
if (sscanf(value, "%u", &bw) != 1)
- return false;
+ return MSG_FAILURE;
DESKWINSET(border_width, bw)
#undef DESKWINSET
#define DESKSET(k, v) \
} else if (streq("window_gap", name)) {
int wg;
if (sscanf(value, "%i", &wg) != 1)
- return false;
+ return MSG_FAILURE;
DESKSET(window_gap, wg)
#undef DESKSET
#define MONDESKSET(k, v) \
} else if (streq("top_padding", name)) {
int tp;
if (sscanf(value, "%i", &tp) != 1)
- return false;
+ return MSG_FAILURE;
MONDESKSET(top_padding, tp)
} else if (streq("right_padding", name)) {
int rp;
if (sscanf(value, "%i", &rp) != 1)
- return false;
+ return MSG_FAILURE;
MONDESKSET(right_padding, rp)
} else if (streq("bottom_padding", name)) {
int bp;
if (sscanf(value, "%i", &bp) != 1)
- return false;
+ return MSG_FAILURE;
MONDESKSET(bottom_padding, bp)
} else if (streq("left_padding", name)) {
int lp;
if (sscanf(value, "%i", &lp) != 1)
- return false;
+ return MSG_FAILURE;
MONDESKSET(left_padding, lp)
#undef MONDESKSET
#define SETSTR(s) \
if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
split_ratio = r;
else
- return false;
- return true;
+ return MSG_FAILURE;
+ return MSG_SUCCESS;
#define SETCOLOR(s) \
} else if (streq(#s, name)) { \
snprintf(s, sizeof(s), "%s", value);
window_hide(m->root);
disable_motion_recorder();
}
- return true;
+ return MSG_SUCCESS;
} else {
- return false;
+ return MSG_FAILURE;
}
#define SETBOOL(s) \
} else if (streq(#s, name)) { \
if (!parse_bool(value, &s)) \
- return false;
+ return MSG_FAILURE;
SETBOOL(borderless_monocle)
SETBOOL(gapless_monocle)
SETBOOL(pointer_follows_monitor)
SETBOOL(remove_disabled_monitor)
#undef SETBOOL
} else {
- return false;
+ return MSG_FAILURE;
}
for (monitor_t *m = mon_head; m != NULL; m = m->next)
for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
arrange(m, d);
- return true;
+ return MSG_SUCCESS;
}
-bool get_setting(coordinates_t loc, char *name, char* rsp)
+int get_setting(coordinates_t loc, char *name, FILE* rsp)
{
if (streq("split_ratio", name))
- snprintf(rsp, BUFSIZ, "%lf", split_ratio);
+ fprintf(rsp, "%lf", split_ratio);
else if (streq("window_gap", name))
if (loc.desktop == NULL)
- return false;
+ return MSG_FAILURE;
else
- snprintf(rsp, BUFSIZ, "%i", loc.desktop->window_gap);
+ fprintf(rsp, "%i", loc.desktop->window_gap);
else if (streq("border_width", name))
if (loc.node != NULL)
- snprintf(rsp, BUFSIZ, "%u", loc.node->client->border_width);
+ fprintf(rsp, "%u", loc.node->client->border_width);
else if (loc.desktop != NULL)
- snprintf(rsp, BUFSIZ, "%u", loc.desktop->border_width);
+ fprintf(rsp, "%u", loc.desktop->border_width);
else
- return false;
+ return MSG_FAILURE;
else if (streq("external_rules_command", name))
- snprintf(rsp, BUFSIZ, "%s", external_rules_command);
+ fprintf(rsp, "%s", external_rules_command);
else if (streq("status_prefix", name))
- snprintf(rsp, BUFSIZ, "%s", status_prefix);
+ fprintf(rsp, "%s", status_prefix);
#define MONDESKGET(k) \
else if (streq(#k, name)) \
if (loc.desktop != NULL) \
- snprintf(rsp, BUFSIZ, "%i", loc.desktop->k); \
+ fprintf(rsp, "%i", loc.desktop->k); \
else if (loc.monitor != NULL) \
- snprintf(rsp, BUFSIZ, "%i", loc.monitor->k); \
+ fprintf(rsp, "%i", loc.monitor->k); \
else \
- return false;
+ return MSG_FAILURE;
MONDESKGET(top_padding)
MONDESKGET(right_padding)
MONDESKGET(bottom_padding)
#undef DESKGET
#define GETCOLOR(s) \
else if (streq(#s, name)) \
- snprintf(rsp, BUFSIZ, "%s", s);
+ fprintf(rsp, "%s", s);
GETCOLOR(focused_border_color)
GETCOLOR(active_border_color)
GETCOLOR(normal_border_color)
#undef GETCOLOR
#define GETBOOL(s) \
else if (streq(#s, name)) \
- snprintf(rsp, BUFSIZ, "%s", BOOLSTR(s));
+ fprintf(rsp, "%s", BOOLSTR(s));
GETBOOL(borderless_monocle)
GETBOOL(gapless_monocle)
GETBOOL(focus_follows_pointer)
GETBOOL(remove_disabled_monitor)
#undef GETBOOL
else
- return false;
- return true;
+ return MSG_FAILURE;
+ return MSG_SUCCESS;
}
bool parse_bool(char *value, bool *b)
#include "tree.h"
#include "query.h"
-void query_monitors(coordinates_t loc, domain_t dom, char *rsp)
+void query_monitors(coordinates_t loc, domain_t dom, FILE *rsp)
{
- char line[MAXLEN];
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
if (loc.monitor != NULL && m != loc.monitor)
continue;
if (dom != DOMAIN_DESKTOP) {
if (dom == DOMAIN_MONITOR) {
- snprintf(line, sizeof(line), "%s\n", m->name);
- strncat(rsp, line, REMLEN(rsp));
+ fprintf(rsp, "%s\n", m->name);
continue;
} else {
- snprintf(line, sizeof(line), "%s %ux%u%+i%+i %i,%i,%i,%i", m->name,
+ fprintf(rsp, "%s %ux%u%+i%+i %i,%i,%i,%i%s\n", m->name,
m->rectangle.width,m->rectangle.height, m->rectangle.x, m->rectangle.y,
- m->top_padding, m->right_padding, m->bottom_padding, m->left_padding);
- strncat(rsp, line, REMLEN(rsp));
- if (m == mon)
- strncat(rsp, " *", REMLEN(rsp));
- strncat(rsp, "\n", REMLEN(rsp));
+ m->top_padding, m->right_padding, m->bottom_padding, m->left_padding,
+ (m == mon ? " *" : ""));
}
}
query_desktops(m, dom, loc, (dom == DOMAIN_DESKTOP ? 0 : 1), rsp);
}
}
-void query_desktops(monitor_t *m, domain_t dom, coordinates_t loc, unsigned int depth, char *rsp)
+void query_desktops(monitor_t *m, domain_t dom, coordinates_t loc, unsigned int depth, FILE *rsp)
{
- char line[MAXLEN];
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
if (loc.desktop != NULL && d != loc.desktop)
continue;
for (unsigned int i = 0; i < depth; i++)
- strncat(rsp, "\t", REMLEN(rsp));
+ fprintf(rsp, "\t");
if (dom == DOMAIN_DESKTOP) {
- snprintf(line, sizeof(line), "%s\n", d->name);
- strncat(rsp, line, REMLEN(rsp));
+ fprintf(rsp, "%s\n", d->name);
continue;
} else {
- snprintf(line, sizeof(line), "%s %u %i %i,%i,%i,%i %c %c", d->name, d->border_width, d->window_gap,
- d->top_padding, d->right_padding, d->bottom_padding, d->left_padding,
- (d->layout == LAYOUT_TILED ? 'T' : 'M'), (d->floating ? 'f' : '-'));
- strncat(rsp, line, REMLEN(rsp));
- if (d == m->desk)
- strncat(rsp, " *", REMLEN(rsp));
- strncat(rsp, "\n", REMLEN(rsp));
+ fprintf(rsp, "%s %u %i %i,%i,%i,%i %c %c%s\n", d->name, d->border_width,
+ d->window_gap,
+ d->top_padding, d->right_padding, d->bottom_padding, d->left_padding,
+ (d->layout == LAYOUT_TILED ? 'T' : 'M'), (d->floating ? 'f' : '-'),
+ (d == m->desk ? " *" : ""));
}
query_tree(d, d->root, rsp, depth + 1);
}
}
-void query_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
+void query_tree(desktop_t *d, node_t *n, FILE *rsp, unsigned int depth)
{
if (n == NULL)
return;
- char line[MAXLEN];
-
for (unsigned int i = 0; i < depth; i++)
- strncat(rsp, "\t", REMLEN(rsp));
+ fprintf(rsp, "\t");
if (is_leaf(n)) {
client_t *c = n->client;
- snprintf(line, sizeof(line), "%c %s %s 0x%X %u %ux%u%+i%+i %c %c%c%c%c%c%c%c%c",
+ fprintf(rsp, "%c %s %s 0x%X %u %ux%u%+i%+i %c %c%c%c%c%c%c%c%c%s\n",
(n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')),
c->class_name, c->instance_name, c->window, c->border_width,
c->floating_rectangle.width, c->floating_rectangle.height,
(n->split_dir == DIR_UP ? 'U' : (n->split_dir == DIR_RIGHT ? 'R' : (n->split_dir == DIR_DOWN ? 'D' : 'L'))),
(c->floating ? 'f' : '-'), (c->pseudo_tiled ? 'd' : '-'), (c->fullscreen ? 'F' : '-'),
(c->urgent ? 'u' : '-'), (c->locked ? 'l' : '-'), (c->sticky ? 's' : '-'),
- (c->private ? 'i' : '-'), (n->split_mode ? 'p' : '-'));
+ (c->private ? 'i' : '-'), (n->split_mode ? 'p' : '-'),
+ (n == d->focus ? " *" : ""));
} else {
- snprintf(line, sizeof(line), "%c %c %lf", (n->split_type == TYPE_HORIZONTAL ? 'H' : 'V'),
+ fprintf(rsp, "%c %c %lf\n", (n->split_type == TYPE_HORIZONTAL ? 'H' : 'V'),
(n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), n->split_ratio);
}
- strncat(rsp, line, REMLEN(rsp));
-
- if (n == d->focus)
- strncat(rsp, " *", REMLEN(rsp));
- strncat(rsp, "\n", REMLEN(rsp));
-
query_tree(d, n->first_child, rsp, depth + 1);
query_tree(d, n->second_child, rsp, depth + 1);
}
-void query_history(coordinates_t loc, char *rsp)
+void query_history(coordinates_t loc, FILE *rsp)
{
- char line[MAXLEN];
for (history_t *h = history_head; h != NULL; h = h->next) {
if ((loc.monitor != NULL && h->loc.monitor != loc.monitor)
|| (loc.desktop != NULL && h->loc.desktop != loc.desktop))
xcb_window_t win = XCB_NONE;
if (h->loc.node != NULL)
win = h->loc.node->client->window;
- snprintf(line, sizeof(line), "%s %s 0x%X", h->loc.monitor->name, h->loc.desktop->name, win);
- strncat(rsp, line, REMLEN(rsp));
- strncat(rsp, "\n", REMLEN(rsp));
+ fprintf(rsp, "%s %s 0x%X\n", h->loc.monitor->name, h->loc.desktop->name, win);
}
}
-void query_stack(char *rsp)
+void query_stack(FILE *rsp)
{
- char line[MAXLEN];
- for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
- snprintf(line, sizeof(line), "0x%X", s->node->client->window);
- strncat(rsp, line, REMLEN(rsp));
- strncat(rsp, "\n", REMLEN(rsp));
- }
+ for (stacking_list_t *s = stack_head; s != NULL; s = s->next)
+ fprintf(rsp, "0x%X\n", s->node->client->window);
}
-void query_windows(coordinates_t loc, char *rsp)
+void query_windows(coordinates_t loc, FILE *rsp)
{
- char line[MAXLEN];
-
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
if (loc.monitor != NULL && m != loc.monitor)
continue;
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
if (loc.node != NULL && n != loc.node)
continue;
- snprintf(line, sizeof(line), "0x%X\n", n->client->window);
- strncat(rsp, line, REMLEN(rsp));
+ fprintf(rsp, "0x%X\n", n->client->window);
}
}
}