Resolve the rule consequence when scheduling rules

Fixes #1163.
This commit is contained in:
Bastien Dejean 2020-07-31 18:21:46 +02:00
parent 5d93323f30
commit 1c795c3351
3 changed files with 23 additions and 25 deletions

View file

@ -426,6 +426,26 @@ void print_pointer_action(pointer_action_t a, FILE *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;
@ -435,29 +455,8 @@ void print_rule_consequence(char **buf, rule_consequence_t *csq)
*rect_buf = '\0';
}
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) \
char *name##_buf = NULL; \
if (name == NULL) { \
name##_buf = malloc(1); \
*name##_buf = '\0'; \
} else { \
asprintf(&name##_buf, "0x%08X", name->id); \
}
PRINT_OBJECT_ID(monitor)
PRINT_OBJECT_ID(desktop)
PRINT_OBJECT_ID(node)
#undef PRINT_OBJECT_ID
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",
monitor_buf == NULL ? "" : monitor_buf,
desktop_buf == NULL ? "" : desktop_buf,
node_buf == NULL ? "" : node_buf,
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 == NULL ? "" : SPLIT_DIR_STR(*csq->split_dir), csq->split_ratio,
@ -465,9 +464,6 @@ void print_rule_consequence(char **buf, rule_consequence_t *csq)
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);
free(rect_buf);
free(monitor_buf);
free(desktop_buf);
free(node_buf);
}
void print_rectangle(char **buf, xcb_rectangle_t *rect)

View file

@ -69,6 +69,7 @@ void print_ignore_request(state_transition_t st, FILE *rsp);
void print_modifier_mask(uint16_t m, FILE *rsp);
void print_button_index(int8_t b, FILE *rsp);
void print_pointer_action(pointer_action_t a, FILE *rsp);
void resolve_rule_consequence(rule_consequence_t *csq);
void print_rule_consequence(char **buf, rule_consequence_t *csq);
void print_rectangle(char **buf, xcb_rectangle_t *rect);
node_select_t make_node_select(void);

View file

@ -343,6 +343,7 @@ bool schedule_rules(xcb_window_t win, rule_consequence_t *csq)
if (external_rules_command[0] == '\0') {
return false;
}
resolve_rule_consequence(csq);
int fds[2];
if (pipe(fds) == -1) {
return false;