]> git.lizzy.rs Git - bspwm.git/commitdiff
Resolve the rule consequence when scheduling rules
authorBastien Dejean <nihilhill@gmail.com>
Fri, 31 Jul 2020 16:21:46 +0000 (18:21 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Fri, 31 Jul 2020 18:38:32 +0000 (20:38 +0200)
Fixes #1163.

src/query.c
src/query.h
src/rule.c

index 0d7e3e08cbf33d09cafee00df5e100a56f33d049..ba0445808a7288c3ba21d61487bd9cdb6c14579f 100644 (file)
@@ -426,15 +426,8 @@ void print_pointer_action(pointer_action_t a, FILE *rsp)
        }
 }
 
-void print_rule_consequence(char **buf, rule_consequence_t *csq)
+void resolve_rule_consequence(rule_consequence_t *csq)
 {
-       char *rect_buf = NULL;
-       print_rectangle(&rect_buf, csq->rect);
-       if (rect_buf == NULL) {
-               rect_buf = malloc(1);
-               *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;
@@ -442,22 +435,28 @@ void print_rule_consequence(char **buf, rule_consequence_t *csq)
        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'; \
+               csq->name##_desc[0] = '\0'; \
        } else { \
-               asprintf(&name##_buf, "0x%08X", name->id); \
+               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;
+       print_rectangle(&rect_buf, csq->rect);
+       if (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",
-               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)
index a6bca75f6cfaafecf94fb627395b7be02075c763..e98f03dbd093b809e2eaea72b888c19f5ce95723 100644 (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);
index 02fdc98be0bbee3a9d1e6f66c3e7ec6ab51237e4..583b2382f710d1f6b4daeb6c5bb74ba0e51c2000 100644 (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;