fprintf(rsp, "\"stickyCount\":%i,", m->sticky_count);
fprintf(rsp, "\"windowGap\":%i,", m->window_gap);
fprintf(rsp, "\"borderWidth\":%u,", m->border_width);
+ fprintf(rsp, "\"borderRadius\":%u,", m->border_radius);
fprintf(rsp, "\"focusedDesktopId\":%u,", m->desk->id);
fprintf(rsp, "\"padding\":");
query_padding(m->padding, rsp);
fprintf(rsp, "\"userLayout\":\"%s\",", LAYOUT_STR(d->user_layout));
fprintf(rsp, "\"windowGap\":%i,", d->window_gap);
fprintf(rsp, "\"borderWidth\":%u,", d->border_width);
+ fprintf(rsp, "\"borderRadius\":%u,", d->border_radius);
fprintf(rsp, "\"focusedNodeId\":%u,", d->focus != NULL ? d->focus->id : 0);
fprintf(rsp, "\"padding\":");
query_padding(d->padding, rsp);
fprintf(rsp, "\"className\":\"%s\",", c->class_name);
fprintf(rsp, "\"instanceName\":\"%s\",", c->instance_name);
fprintf(rsp, "\"borderWidth\":%u,", c->border_width);
+ fprintf(rsp, "\"borderRadius\":%u,", c->border_radius);
fprintf(rsp, "\"state\":\"%s\",", STATE_STR(c->state));
fprintf(rsp, "\"lastState\":\"%s\",", STATE_STR(c->last_state));
fprintf(rsp, "\"layer\":\"%s\",", LAYER_STR(c->layer));
fprintf(rsp, "]");
}
-int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
+int query_node_ids(coordinates_t *mon_ref, coordinates_t *desk_ref, coordinates_t* ref, coordinates_t *trg, monitor_select_t *mon_sel, desktop_select_t *desk_sel, node_select_t *sel, FILE *rsp)
{
int count = 0;
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
- if (trg->monitor != NULL && m != trg->monitor) {
+ coordinates_t loc = {m, NULL, NULL};
+ if ((trg->monitor != NULL && m != trg->monitor) ||
+ (mon_sel != NULL && !monitor_matches(&loc, mon_ref, mon_sel))) {
continue;
}
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
- if (trg->desktop != NULL && d != trg->desktop) {
+ coordinates_t loc = {m, d, NULL};
+ if ((trg->desktop != NULL && d != trg->desktop) ||
+ (desk_sel != NULL && !desktop_matches(&loc, desk_ref, desk_sel))) {
continue;
}
count += query_node_ids_in(d->root, d, m, ref, trg, sel, rsp);
return count;
}
-int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
+int query_desktop_ids(coordinates_t* mon_ref, coordinates_t *ref, coordinates_t *trg, monitor_select_t *mon_sel, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
{
int count = 0;
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
- if (trg->monitor != NULL && m != trg->monitor) {
+ coordinates_t loc = {m, NULL, NULL};
+ if ((trg->monitor != NULL && m != trg->monitor) ||
+ (mon_sel != NULL && !monitor_matches(&loc, mon_ref, mon_sel))) {
continue;
}
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
coordinates_t loc = {m, NULL, NULL};
if ((trg->monitor != NULL && m != trg->monitor) ||
- (sel != NULL && !monitor_matches(&loc, ref, sel))) {
+ (sel != NULL && !monitor_matches(&loc, ref, sel))) {
continue;
}
printer(m, rsp);
}
}
+void resolve_rule_consequence(rule_consequence_t *csq)
+{
+ coordinates_t ref = {mon, mon->desk, mon->desk->focus};
+ coordinates_t dst = {NULL, NULL, NULL};
+ monitor_t *monitor = monitor_from_desc(csq->monitor_desc, &ref, &dst) != SELECTOR_OK ? NULL : dst.monitor;
+ desktop_t *desktop = desktop_from_desc(csq->desktop_desc, &ref, &dst) != SELECTOR_OK ? NULL : dst.desktop;
+ node_t *node = node_from_desc(csq->node_desc, &ref, &dst) != SELECTOR_OK ? NULL : dst.node;
+
+#define PRINT_OBJECT_ID(name) \
+ if (name == NULL) { \
+ csq->name##_desc[0] = '\0'; \
+ } else { \
+ snprintf(csq->name##_desc, 11, "0x%08X", name->id); \
+ }
+ PRINT_OBJECT_ID(monitor)
+ PRINT_OBJECT_ID(desktop)
+ PRINT_OBJECT_ID(node)
+#undef PRINT_OBJECT_ID
+}
+
void print_rule_consequence(char **buf, rule_consequence_t *csq)
{
char *rect_buf = NULL;
rect_buf = malloc(1);
*rect_buf = '\0';
}
+
asprintf(buf, "monitor=%s desktop=%s node=%s state=%s layer=%s split_dir=%s split_ratio=%lf hidden=%s sticky=%s private=%s locked=%s marked=%s center=%s follow=%s manage=%s focus=%s border=%s rectangle=%s",
csq->monitor_desc, csq->desktop_desc, csq->node_desc,
csq->state == NULL ? "" : STATE_STR(*csq->state),
csq->layer == NULL ? "" : LAYER_STR(*csq->layer),
- csq->split_dir, csq->split_ratio,
+ csq->split_dir == NULL ? "" : SPLIT_DIR_STR(*csq->split_dir), csq->split_ratio,
ON_OFF_STR(csq->hidden), ON_OFF_STR(csq->sticky), ON_OFF_STR(csq->private),
ON_OFF_STR(csq->locked), ON_OFF_STR(csq->marked), ON_OFF_STR(csq->center), ON_OFF_STR(csq->follow),
ON_OFF_STR(csq->manage), ON_OFF_STR(csq->focus), ON_OFF_STR(csq->border), rect_buf);
.focused = OPTION_NONE,
.active = OPTION_NONE,
.urgent = OPTION_NONE,
- .local = OPTION_NONE
+ .local = OPTION_NONE,
+ .tiled = OPTION_NONE,
+ .monocle = OPTION_NONE,
+ .user_tiled = OPTION_NONE,
+ .user_monocle = OPTION_NONE
};
return sel;
}
int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
{
+ dst->node = NULL;
+
coordinates_t ref_copy = *ref;
ref = &ref_copy;
char *desc_copy = copy_string(desc, strlen(desc));
char *path = strrchr(desc, '@');
char *colon = strrchr(desc, ':');
- /* Discard hashes inside a DESKTOP_SEL */
+ /* Adjust or discard hashes inside a DESKTOP_SEL, e.g. `newest#@prev#older:/1/2` */
if (hash != NULL && colon != NULL && path != NULL &&
path < hash && hash < colon) {
if (path > desc && *(path - 1) == '#') {
}
}
+ /* Discard colons within references, e.g. `@next.occupied:/#any.descendant_of.window` */
+ if (colon != NULL && hash != NULL && colon < hash) {
+ colon = NULL;
+ }
+
node_select_t sel = make_node_select();
if (!parse_node_modifiers(colon != NULL ? colon : desc, &sel)) {
return SELECTOR_BAD_MODIFIERS;
}
- dst->node = NULL;
-
direction_t dir;
cycle_dir_t cyc;
history_dir_t hdi;
} else if (streq("pointed", desc)) {
xcb_window_t win = XCB_NONE;
query_pointer(&win, NULL);
- if (locate_window(win, dst) && node_matches(dst, ref, &sel)) {
+ if (locate_leaf(win, dst) && node_matches(dst, ref, &sel)) {
return SELECTOR_OK;
} else {
return SELECTOR_INVALID;
int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
{
+ dst->desktop = NULL;
+
if (*desc == '%') {
locate_desktop(desc + 1, dst);
goto end;
desc = desc_copy;
char *hash = strrchr(desc, '#');
+ char *colon = strrchr(desc, ':');
+
+ /* Discard hashes inside a MONITOR_SEL, e.g. `primary#next:focused` */
+ if (hash != NULL && colon != NULL && hash < colon) {
+ hash = NULL;
+ }
if (hash != NULL) {
*hash = '\0';
}
}
+ /* Discard colons within references, e.g. `DisplayPort-1:focused#next.local` */
+ if (colon != NULL && hash != NULL && colon < hash) {
+ colon = NULL;
+ }
+
desktop_select_t sel = make_desktop_select();
- char *colon = strrchr(desc, ':');
if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
free(desc_copy);
return SELECTOR_BAD_MODIFIERS;
}
- dst->desktop = NULL;
-
cycle_dir_t cyc;
history_dir_t hdi;
uint16_t idx;
int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
{
+ dst->monitor = NULL;
+
if (*desc == '%') {
locate_monitor(desc + 1, dst);
goto end;
return SELECTOR_BAD_MODIFIERS;
}
- dst->monitor = NULL;
-
direction_t dir;
cycle_dir_t cyc;
history_dir_t hdi;
return SELECTOR_OK;
}
+bool locate_leaf(xcb_window_t win, coordinates_t *loc)
+{
+ 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)) {
+ if (n->id == win) {
+ loc->monitor = m;
+ loc->desktop = d;
+ loc->node = n;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
bool locate_window(xcb_window_t win, coordinates_t *loc)
{
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
NFLAG(marked)
#undef NFLAG
- if (loc->node->client == NULL &&
- (sel->same_class != OPTION_NONE ||
- sel->tiled != OPTION_NONE ||
- sel->pseudo_tiled != OPTION_NONE ||
- sel->floating != OPTION_NONE ||
- sel->fullscreen != OPTION_NONE ||
- sel->below != OPTION_NONE ||
- sel->normal != OPTION_NONE ||
- sel->above != OPTION_NONE ||
- sel->urgent != OPTION_NONE)) {
- return false;
- }
-
- if (ref->node != NULL && ref->node->client != NULL &&
- sel->same_class != OPTION_NONE &&
- streq(loc->node->client->class_name, ref->node->client->class_name)
- ? sel->same_class == OPTION_FALSE
- : sel->same_class == OPTION_TRUE) {
- return false;
+#define NSPLIT(p, e) \
+ if (sel->p != OPTION_NONE && \
+ loc->node->split_type != e \
+ ? sel->p == OPTION_TRUE \
+ : sel->p == OPTION_FALSE) { \
+ return false; \
}
+ NSPLIT(horizontal, TYPE_HORIZONTAL)
+ NSPLIT(vertical, TYPE_VERTICAL)
+#undef NSPLIT
if (sel->descendant_of != OPTION_NONE &&
!is_descendant(loc->node, ref->node)
return false;
}
+ if (loc->node->client == NULL) {
+ if (sel->same_class == OPTION_TRUE ||
+ sel->tiled == OPTION_TRUE ||
+ sel->pseudo_tiled == OPTION_TRUE ||
+ sel->floating == OPTION_TRUE ||
+ sel->fullscreen == OPTION_TRUE ||
+ sel->below == OPTION_TRUE ||
+ sel->normal == OPTION_TRUE ||
+ sel->above == OPTION_TRUE ||
+ sel->urgent == OPTION_TRUE) {
+ return false;
+ }
+ return true;
+ }
+
+ if (ref->node != NULL && ref->node->client != NULL &&
+ sel->same_class != OPTION_NONE &&
+ streq(loc->node->client->class_name, ref->node->client->class_name)
+ ? sel->same_class == OPTION_FALSE
+ : sel->same_class == OPTION_TRUE) {
+ return false;
+ }
+
#define WSTATE(p, e) \
if (sel->p != OPTION_NONE && \
loc->node->client->state != e \
WFLAG(urgent)
#undef WFLAG
- if (sel->horizontal != OPTION_NONE &&
- loc->node->split_type != TYPE_HORIZONTAL
- ? sel->horizontal == OPTION_TRUE
- : sel->horizontal == OPTION_FALSE) {
- return false;
- }
-
- if (sel->vertical != OPTION_NONE &&
- loc->node->split_type != TYPE_VERTICAL
- ? sel->vertical == OPTION_TRUE
- : sel->vertical == OPTION_FALSE) {
- return false;
- }
-
return true;
}
return false;
}
+#define DLAYOUT(p, e) \
+ if (sel->p != OPTION_NONE && \
+ loc->desktop->layout != e \
+ ? sel->p == OPTION_TRUE \
+ : sel->p == OPTION_FALSE) { \
+ return false; \
+ }
+ DLAYOUT(tiled, LAYOUT_TILED)
+ DLAYOUT(monocle, LAYOUT_MONOCLE)
+#undef DLAYOUT
+
+#define DUSERLAYOUT(p, e) \
+ if (sel->p != OPTION_NONE && \
+ loc->desktop->user_layout != e \
+ ? sel->p == OPTION_TRUE \
+ : sel->p == OPTION_FALSE) { \
+ return false; \
+ }
+ DUSERLAYOUT(user_tiled, LAYOUT_TILED)
+ DUSERLAYOUT(user_monocle, LAYOUT_MONOCLE)
+#undef DUSERLAYOUT
+
return true;
}