#include <stdlib.h>
#include <errno.h>
#include "settings.h"
-#include "messages.h"
#include "query.h"
-#include "restore.h"
-#include "common.h"
-#include "types.h"
#include "bspwm.h"
-#include "ewmh.h"
-#include "helpers.h"
+#include "tree.h"
+#include "desktop.h"
+#include "monitor.h"
#include "window.h"
+#include "rule.h"
+#include "restore.h"
#include "events.h"
-#include "tree.h"
-#include "rules.h"
+#include "ewmh.h"
+#include "messages.h"
bool cmd_window(char **args, int num)
{
direction_t dir;
if (!parse_direction(*args, &dir))
return false;
- num--, args++;
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 {
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;
} else {
return false;
}
+ } else if (streq("-s", *args) || streq("--swap", *args)) {
+ num--, args++;
+ if (num < 1)
+ return false;
+ coordinates_t dst;
+ if (desktop_from_desc(*args, &trg, &dst) && trg.monitor == dst.monitor)
+ swap_desktops(dst.monitor, trg.desktop, dst.desktop);
+ else
+ return false;
} else if (streq("-l", *args) || streq("--layout", *args)) {
num--, args++;
if (num < 1)
strncpy(trg.desktop->name, *args, sizeof(trg.desktop->name));
ewmh_update_desktop_names();
put_status();
- } else if (streq("-r", *args) || streq("--rm", *args)) {
+ } else if (streq("-r", *args) || streq("--remove", *args)) {
if (trg.desktop->root == NULL
&& trg.monitor->desk_head != trg.monitor->desk_tail) {
remove_desktop(trg.monitor, trg.desktop);
- desktop_show(trg.monitor->desk);
+ show_desktop(trg.monitor->desk);
update_current();
return true;
} else {
if (parse_flip(*args, &flp)) {
flip_tree(trg.desktop->root, flp);
dirty = true;
+ } else {
+ return false;
}
} else if (streq("-R", *args) || streq("--rotate", *args)) {
num--, args++;
if (num < 1)
return false;
- int rot = atoi(*args);
- while (rot < 0)
- rot += 360;
- while (rot > 359)
- rot -= 360;
- if ((rot % 90) != 0) {
- return false;
- } else {
- rotate_tree(trg.desktop->root, rot);
+ int deg;
+ if (parse_degree(*args, °)) {
+ rotate_tree(trg.desktop->root, deg);
dirty = true;
+ } else {
+ return false;
}
} else if (streq("-B", *args) || streq("--balance", *args)) {
balance_tree(trg.desktop->root);
coordinates_t dst;
if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
remove_desktop(dst.monitor, dst.desktop);
- desktop_show(dst.monitor->desk);
+ show_desktop(dst.monitor->desk);
}
num--, args++;
}
- } else if (streq("-p", *args) || streq("--pad", *args)) {
- num--, args++;
- if (num < 4)
- return false;
- char values[MAXLEN];
- snprintf(values, sizeof(values), "%s %s %s %s", args[0], args[1], args[2], args[3]);
- num -= 3;
- args += 3;
- if (sscanf(values, "%i %i %i %i", &trg.monitor->top_padding, &trg.monitor->right_padding, &trg.monitor->bottom_padding, &trg.monitor->left_padding) == 4)
- for (desktop_t *d = trg.monitor->desk_head; d != NULL; d = d->next)
- arrange(trg.monitor, d);
- else
- return false;
} else if (streq("-n", *args) || streq("--rename", *args)) {
num--, args++;
if (num < 1)
return false;
strncpy(trg.monitor->name, *args, sizeof(trg.monitor->name));
put_status();
+ } else if (streq("-s", *args) || streq("--swap", *args)) {
+ num--, args++;
+ if (num < 1)
+ return false;
+ coordinates_t dst;
+ if (monitor_from_desc(*args, &trg, &dst))
+ swap_monitors(trg.monitor, dst.monitor);
+ else
+ return false;
} else {
return false;
}
while (num > 0) {
if (streq("--floating", *args)) {
rule->effect.floating = true;
+ } else if (streq("--fullscreen", *args)) {
+ rule->effect.fullscreen = true;
+ } else if (streq("--locked", *args)) {
+ rule->effect.locked = true;
} else if (streq("--follow", *args)) {
rule->effect.follow = true;
} else if (streq("--focus", *args)) {
rule->effect.focus = true;
+ } else if (streq("--unmanage", *args)) {
+ rule->effect.unmanage = true;
+ } else if (streq("--one-shot", *args)) {
+ rule->one_shot = true;
} else if (streq("-d", *args) || streq("--desktop", *args)) {
num--, args++;
if (num < 1) {
num--, args++;
}
add_rule(rule);
- } else if (streq("-r", *args) || streq("--rm", *args)) {
+ } else if (streq("-r", *args) || streq("--remove", *args)) {
num--, args++;
if (num < 1)
return false;
while (num > 0) {
if (sscanf(*args, "%X", &uid) == 1)
remove_rule_by_uid(uid);
+ else if (streq("tail", *args))
+ remove_rule(rule_tail);
+ else if (streq("head", *args))
+ remove_rule(rule_head);
else
return false;
num--, args++;
}
bool cmd_config(char **args, int num, char *rsp) {
+ if (num < 1)
+ return false;
+ coordinates_t ref = {mon, mon->desk, mon->desk->focus};
+ coordinates_t trg = {NULL, NULL, NULL};
+ if (*args[0] == OPT_CHR) {
+ if (streq("-d", *args) || streq("--desktop", *args)) {
+ num--, args++;
+ if (num < 1)
+ return false;
+ if (!desktop_from_desc(*args, &ref, &trg))
+ return false;
+ } else if (streq("-m", *args) || streq("--monitor", *args)) {
+ num--, args++;
+ if (num < 1)
+ return false;
+ if (!monitor_from_desc(*args, &ref, &trg))
+ return false;
+ } else {
+ return false;
+ }
+ num--, args++;
+ }
if (num == 2)
- return set_setting(*args, *(args + 1));
+ return set_setting(trg, *args, *(args + 1));
else if (num == 1)
- return get_setting(*args, rsp);
+ return get_setting(trg, *args, rsp);
else
return false;
}
return false;
}
-bool set_setting(char *name, char *value)
+bool set_setting(coordinates_t loc, char *name, char *value)
{
if (streq("border_width", name)) {
if (sscanf(value, "%u", &border_width) != 1)
return false;
} else if (streq("window_gap", name)) {
- if (sscanf(value, "%i", &window_gap) != 1)
+ int wg;
+ if (sscanf(value, "%i", &wg) != 1)
return false;
+ if (loc.desktop != NULL)
+ loc.desktop->window_gap = wg;
+ else if (loc.monitor != NULL)
+ for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next)
+ d->window_gap = wg;
+ else
+ for (monitor_t *m = mon_head; m != NULL; m = m->next)
+ for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
+ d->window_gap = wg;
+#define MONSET(k) \
+ } else if (streq(#k, name)) { \
+ int v; \
+ if (sscanf(value, "%i", &v) != 1) \
+ return false; \
+ if (loc.monitor != NULL) \
+ loc.monitor->k = v; \
+ else \
+ for (monitor_t *m = mon_head; m!= NULL; m = m->next) \
+ m->k = v;
+ MONSET(top_padding)
+ MONSET(right_padding)
+ MONSET(bottom_padding)
+ MONSET(left_padding)
+#undef MONSET
} else if (streq("split_ratio", name)) {
double rat;
if (sscanf(value, "%lf", &rat) == 1 && rat > 0 && rat < 1)
return false;
#define SETCOLOR(s) \
} else if (streq(#s, name)) { \
- if (get_color(value, &s ## _pxl)) \
- strncpy(s, value, sizeof(s)); \
- else \
- return false;
+ strncpy(s, value, sizeof(s));
SETCOLOR(focused_border_color)
SETCOLOR(active_border_color)
SETCOLOR(normal_border_color)
SETBOOL(borderless_monocle)
SETBOOL(gapless_monocle)
SETBOOL(pointer_follows_monitor)
- SETBOOL(adaptative_raise)
- SETBOOL(apply_shadow_property)
+ SETBOOL(apply_floating_atom)
SETBOOL(auto_alternate)
SETBOOL(auto_cancel)
SETBOOL(history_aware_focus)
#undef SETBOOL
- } else if (streq("wm_name", name)) {
- strncpy(wm_name, value, sizeof(wm_name));
- ewmh_update_wm_name();
- return true;
} else {
return false;
}
return true;
}
-bool get_setting(char *name, char* rsp)
+bool get_setting(coordinates_t loc, char *name, char* rsp)
{
if (streq("border_width", name))
snprintf(rsp, BUFSIZ, "%u", border_width);
else if (streq("split_ratio", name))
snprintf(rsp, BUFSIZ, "%lf", split_ratio);
else if (streq("window_gap", name))
- snprintf(rsp, BUFSIZ, "%i", window_gap);
+ if (loc.desktop == NULL)
+ return false;
+ else
+ snprintf(rsp, BUFSIZ, "%i", loc.desktop->window_gap);
+#define MONGET(k) \
+ else if (streq(#k, name)) \
+ if (loc.monitor == NULL) \
+ return false; \
+ else \
+ snprintf(rsp, BUFSIZ, "%i", loc.monitor->k);
+ MONGET(top_padding)
+ MONGET(right_padding)
+ MONGET(bottom_padding)
+ MONGET(left_padding)
+#undef MONGET
#define GETCOLOR(s) \
else if (streq(#s, name)) \
- snprintf(rsp, BUFSIZ, "%s (%06X)", s, s##_pxl);
+ snprintf(rsp, BUFSIZ, "%s", s);
GETCOLOR(focused_border_color)
GETCOLOR(active_border_color)
GETCOLOR(normal_border_color)
GETBOOL(gapless_monocle)
GETBOOL(focus_follows_pointer)
GETBOOL(pointer_follows_monitor)
- GETBOOL(adaptative_raise)
- GETBOOL(apply_shadow_property)
+ GETBOOL(apply_floating_atom)
GETBOOL(auto_alternate)
GETBOOL(auto_cancel)
GETBOOL(history_aware_focus)
#undef GETBOOL
- else if (streq("wm_name", name))
- snprintf(rsp, BUFSIZ, "%s", wm_name);
else
return false;
return true;
return false;
}
+bool parse_degree(char *s, int *d)
+{
+ int i = atoi(s);
+ while (i < 0)
+ i += 360;
+ while (i > 359)
+ i -= 360;
+ if ((i % 90) != 0) {
+ return false;
+ } else {
+ *d = i;
+ return true;
+ }
+}
+
bool parse_window_id(char *s, long int *i)
{
char *end;
*i = ret;
return true;
}
+
+bool parse_index(char *s, int *i)
+{
+ return sscanf(s, "^%i", i) == 1;
+}