-/* Copyright (c) 2012-2014, Bastien Dejean
+/* Copyright (c) 2012, Bastien Dejean
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those
- * of the authors and should not be interpreted as representing official policies,
- * either expressed or implied, of the FreeBSD Project.
*/
#include <errno.h>
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;
} else {
return MSG_FAILURE;
}
- } else if (streq("-t", *args) || streq("--toggle", *args)) {
+ } 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;
if (val == NULL) {
a = ALTER_TOGGLE;
} else {
- if (parse_bool(val, &b))
+ if (parse_bool(val, &b)) {
a = ALTER_SET;
- else
+ } else {
return MSG_FAILURE;
+ }
}
- if (streq("fullscreen", key)) {
- set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
- dirty = true;
- } else if (streq("pseudo_tiled", key)) {
- set_pseudo_tiled(trg.node, (a == ALTER_SET ? b : !trg.node->client->pseudo_tiled));
- 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)) {
+ 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));
num--, args++;
if (num < 1)
return MSG_SYNTAX;
- if (!is_tiled(trg.node->client) ||
+ if (IS_FLOATING(trg.node->client) ||
trg.desktop->layout != LAYOUT_TILED)
return MSG_FAILURE;
if (streq("cancel", *args)) {
num--, args++;
if (num < 2)
return MSG_SYNTAX;
- if (!is_tiled(trg.node->client))
+ if (IS_FLOATING(trg.node->client))
return MSG_FAILURE;
direction_t dir;
if (!parse_direction(*args, &dir))
} 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_FAILURE;
}
if (auto_alternate && dst.desktop == mon->desk) {
- desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
+ desktop_select_t sel = make_desktop_select();
history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
}
focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
else
return MSG_FAILURE;
+ } else if (streq("-b", *args) || streq("--bubble", *args)) {
+ num--, args++;
+ if (num < 1)
+ return MSG_SYNTAX;
+ cycle_dir_t cyc;
+ if (parse_cycle_direction(*args, &cyc)) {
+ desktop_t *d = trg.desktop;
+ if (cyc == CYCLE_PREV) {
+ if (d->prev == NULL) {
+ while (d->next != NULL) {
+ swap_desktops(trg.monitor, d, trg.monitor, d->next);
+ }
+ } else {
+ swap_desktops(trg.monitor, d, trg.monitor, d->prev);
+ }
+ } else {
+ if (d->next == NULL) {
+ while (d->prev != NULL) {
+ swap_desktops(trg.monitor, d, trg.monitor, d->prev);
+ }
+ } else {
+ swap_desktops(trg.monitor, d, trg.monitor, d->next);
+ }
+ }
+ } else {
+ return MSG_FAILURE;
+ }
} else if (streq("-l", *args) || streq("--layout", *args)) {
num--, args++;
if (num < 1)
num--, args++;
if (num < 1)
return MSG_SYNTAX;
- snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
- ewmh_update_desktop_names();
- put_status();
+ rename_desktop(trg.monitor, trg.desktop, *args);
} else if (streq("-r", *args) || streq("--remove", *args)) {
if (trg.desktop->root == NULL &&
trg.monitor->desk_head != trg.monitor->desk_tail) {
} else {
return MSG_FAILURE;
}
- } else if (streq("-t", *args) || streq("--toggle", *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("floating", key))
- trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
- else
- return MSG_FAILURE;
- } else {
- return MSG_SYNTAX;
}
num--, args++;
}
return MSG_FAILURE;
}
if (auto_alternate && dst.monitor == mon) {
- desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
+ desktop_select_t sel = make_desktop_select();
history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
}
focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
return MSG_SYNTAX;
desktop_t *d = trg.monitor->desk_head;
while (num > 0 && d != NULL) {
- snprintf(d->name, sizeof(d->name), "%s", *args);
+ rename_desktop(trg.monitor, d, *args);
initialize_desktop(d);
arrange(trg.monitor, d);
d = d->next;
num--, args++;
}
- put_status();
+ put_status(SBSC_MASK_REPORT);
while (num > 0) {
add_desktop(trg.monitor, make_desktop(*args));
num--, args++;
}
} else if (streq("-n", *args) || streq("--rename", *args)) {
num--, args++;
- if (num < 1)
+ if (num < 1) {
return MSG_SYNTAX;
- snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
- put_status();
+ }
+ rename_monitor(trg.monitor, *args);
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
if (num < 1)
} else if (streq("--toggle-visibility", *args)) {
toggle_visibility();
} else if (streq("--subscribe", *args)) {
+ num--, args++;
+ int field = 0;
+ if (num < 1) {
+ field = SBSC_MASK_REPORT;
+ } else {
+ subscriber_mask_t mask;
+ while (num > 0) {
+ if (parse_subscriber_mask(*args, &mask)) {
+ field |= mask;
+ } else {
+ return MSG_SYNTAX;
+ }
+ num--, args++;
+ }
+ }
+ add_subscriber(rsp, field);
return MSG_SUBSCRIBE;
} else if (streq("--get-status", *args)) {
- print_status(rsp);
+ print_report(rsp);
} else if (streq("--record-history", *args)) {
num--, args++;
if (num < 1)
if (loc.desktop != NULL) \
loc.desktop->k = v; \
else if (loc.monitor != NULL) \
- for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
- d->k = v; \
+ return MSG_SYNTAX; \
else \
k = v;
} else if (streq("window_gap", name)) {
#undef MONDESKSET
#define SETSTR(s) \
} else if (streq(#s, name)) { \
- return snprintf(s, sizeof(s), "%s", value) >= 0;
+ if (snprintf(s, sizeof(s), "%s", value) < 0) \
+ return MSG_FAILURE;
SETSTR(external_rules_command)
SETSTR(status_prefix)
#undef SETSTR
SETCOLOR(normal_private_border_color)
SETCOLOR(urgent_border_color)
#undef SETCOLOR
+ } else if (streq("initial_polarity", name)) {
+ child_polarity_t p;
+ if (parse_child_polarity(value, &p)) {
+ initial_polarity = p;
+ } else {
+ return MSG_FAILURE;
+ }
} else if (streq("focus_follows_pointer", name)) {
bool b;
if (parse_bool(value, &b) && b != focus_follows_pointer) {
focus_follows_pointer = b;
- for (monitor_t *m = mon_head; m != NULL; m = m->next)
- for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
+ uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
+ for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+ for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
- uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
}
+ }
+ }
if (focus_follows_pointer) {
- for (monitor_t *m = mon_head; m != NULL; m = m->next)
+ for (monitor_t *m = mon_head; m != NULL; m = m->next) {
window_show(m->root);
- enable_motion_recorder();
+ }
} else {
- for (monitor_t *m = mon_head; m != NULL; m = m->next)
+ for (monitor_t *m = mon_head; m != NULL; m = m->next) {
window_hide(m->root);
+ }
disable_motion_recorder();
}
return MSG_SUCCESS;
return MSG_FAILURE;
SETBOOL(borderless_monocle)
SETBOOL(gapless_monocle)
+ SETBOOL(leaf_monocle)
SETBOOL(pointer_follows_focus)
SETBOOL(pointer_follows_monitor)
- SETBOOL(apply_floating_atom)
SETBOOL(auto_alternate)
SETBOOL(auto_cancel)
SETBOOL(history_aware_focus)
SETBOOL(focus_by_distance)
SETBOOL(ignore_ewmh_focus)
+ SETBOOL(center_pseudo_tiled)
#undef SETBOOL
#define SETMONBOOL(s) \
} else if (streq(#s, name)) { \
else if (streq("window_gap", name))
if (loc.desktop != NULL)
fprintf(rsp, "%i", loc.desktop->window_gap);
+ else if (loc.monitor != NULL)
+ return MSG_SYNTAX;
else
fprintf(rsp, "%i", window_gap);
else if (streq("border_width", name))
fprintf(rsp, "%s", external_rules_command);
else if (streq("status_prefix", name))
fprintf(rsp, "%s", status_prefix);
+ else if (streq("initial_polarity", name))
+ fprintf(rsp, "%s", initial_polarity == FIRST_CHILD ? "first_child" : "second_child");
#define MONDESKGET(k) \
else if (streq(#k, name)) \
if (loc.desktop != NULL) \
fprintf(rsp, "%s", BOOLSTR(s));
GETBOOL(borderless_monocle)
GETBOOL(gapless_monocle)
+ GETBOOL(leaf_monocle)
GETBOOL(focus_follows_pointer)
GETBOOL(pointer_follows_focus)
GETBOOL(pointer_follows_monitor)
- GETBOOL(apply_floating_atom)
GETBOOL(auto_alternate)
GETBOOL(auto_cancel)
GETBOOL(history_aware_focus)
GETBOOL(focus_by_distance)
GETBOOL(ignore_ewmh_focus)
+ GETBOOL(center_pseudo_tiled)
GETBOOL(remove_disabled_monitors)
GETBOOL(remove_unplugged_monitors)
GETBOOL(merge_overlapping_monitors)
#undef GETBOOL
else
return MSG_FAILURE;
+ fprintf(rsp, "\n");
return MSG_SUCCESS;
}
+bool parse_subscriber_mask(char *s, subscriber_mask_t *mask)
+{
+ if (streq("all", s)) {
+ *mask = SBSC_MASK_ALL;
+ } else if (streq("window", s)) {
+ *mask = SBSC_MASK_WINDOW;
+ } else if (streq("desktop", s)) {
+ *mask = SBSC_MASK_DESKTOP;
+ } else if (streq("monitor", s)) {
+ *mask = SBSC_MASK_MONITOR;
+ } else if (streq("window_manage", s)) {
+ *mask = SBSC_MASK_WINDOW_MANAGE;
+ } else if (streq("window_unmanage", s)) {
+ *mask = SBSC_MASK_WINDOW_UNMANAGE;
+ } else if (streq("window_swap", s)) {
+ *mask = SBSC_MASK_WINDOW_SWAP;
+ } else if (streq("window_transfer", s)) {
+ *mask = SBSC_MASK_WINDOW_TRANSFER;
+ } else if (streq("window_focus", s)) {
+ *mask = SBSC_MASK_WINDOW_FOCUS;
+ } else if (streq("window_activate", s)) {
+ *mask = SBSC_MASK_WINDOW_ACTIVATE;
+ } else if (streq("window_geometry", s)) {
+ *mask = SBSC_MASK_WINDOW_GEOMETRY;
+ } else if (streq("window_state", s)) {
+ *mask = SBSC_MASK_WINDOW_STATE;
+ } else if (streq("window_flag", s)) {
+ *mask = SBSC_MASK_WINDOW_FLAG;
+ } else if (streq("window_layer", s)) {
+ *mask = SBSC_MASK_WINDOW_LAYER;
+ } else if (streq("desktop_add", s)) {
+ *mask = SBSC_MASK_DESKTOP_ADD;
+ } else if (streq("desktop_rename", s)) {
+ *mask = SBSC_MASK_DESKTOP_RENAME;
+ } else if (streq("desktop_remove", s)) {
+ *mask = SBSC_MASK_DESKTOP_REMOVE;
+ } else if (streq("desktop_swap", s)) {
+ *mask = SBSC_MASK_DESKTOP_SWAP;
+ } else if (streq("desktop_transfer", s)) {
+ *mask = SBSC_MASK_DESKTOP_TRANSFER;
+ } else if (streq("desktop_focus", s)) {
+ *mask = SBSC_MASK_DESKTOP_FOCUS;
+ } else if (streq("desktop_layout", s)) {
+ *mask = SBSC_MASK_DESKTOP_LAYOUT;
+ } else if (streq("monitor_add", s)) {
+ *mask = SBSC_MASK_MONITOR_ADD;
+ } else if (streq("monitor_rename", s)) {
+ *mask = SBSC_MASK_MONITOR_RENAME;
+ } else if (streq("monitor_remove", s)) {
+ *mask = SBSC_MASK_MONITOR_REMOVE;
+ } else if (streq("monitor_focus", s)) {
+ *mask = SBSC_MASK_MONITOR_FOCUS;
+ } else if (streq("monitor_geometry", s)) {
+ *mask = SBSC_MASK_MONITOR_GEOMETRY;
+ } else if (streq("report", s)) {
+ *mask = SBSC_MASK_REPORT;
+ } else {
+ return false;
+ }
+ return true;
+}
+
bool parse_bool(char *value, bool *b)
{
if (streq("true", value) || streq("on", value)) {
return false;
}
+bool parse_client_state(char *s, client_state_t *t)
+{
+ if (streq("tiled", s)) {
+ *t = STATE_TILED;
+ return true;
+ } else if (streq("pseudo_tiled", s)) {
+ *t = STATE_PSEUDO_TILED;
+ return true;
+ } else if (streq("floating", s)) {
+ *t = STATE_FLOATING;
+ return true;
+ } else if (streq("fullscreen", s)) {
+ *t = STATE_FULLSCREEN;
+ return true;
+ }
+ return false;
+}
+
+bool parse_stack_layer(char *s, stack_layer_t *l)
+{
+ if (streq("below", s)) {
+ *l = LAYER_BELOW;
+ return true;
+ } else if (streq("normal", s)) {
+ *l = LAYER_NORMAL;
+ return true;
+ } else if (streq("above", s)) {
+ *l = LAYER_ABOVE;
+ return true;
+ }
+ return false;
+}
+
bool parse_direction(char *s, direction_t *d)
{
if (streq("right", s)) {
return false;
}
+bool parse_child_polarity(char *s, child_polarity_t *p)
+{
+ if (streq("first_child", s)) {
+ *p = FIRST_CHILD;
+ return true;
+ } else if (streq("second_child", s)) {
+ *p = SECOND_CHILD;
+ return true;
+ }
+ return false;
+}
+
bool parse_degree(char *s, int *d)
{
int i = atoi(s);