]> git.lizzy.rs Git - bspwm.git/commitdiff
Pass intermediate conseq. as arg. to ext. rules
authorBastien Dejean <nihilhill@gmail.com>
Fri, 29 Sep 2017 09:19:53 +0000 (11:19 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Fri, 29 Sep 2017 09:19:53 +0000 (11:19 +0200)
Inside the external rules script, `eval "$4"` provides a convenient way
of accessing the current values.

doc/bspwm.1
doc/bspwm.1.asciidoc
src/helpers.c
src/helpers.h
src/query.c
src/query.h
src/rule.c

index aca0334b398288aad0e058c9dfdfa631cb7e04ca..0b20eeb4ea44f3fb94277ae2abfd3a366b9424a4 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: bspwm
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      Date: 09/08/2017
+.\"      Date: 09/29/2017
 .\"    Manual: Bspwm Manual
-.\"    Source: Bspwm 0.9.3-26-g412da35
+.\"    Source: Bspwm 0.9.3-30-gd953f6f
 .\"  Language: English
 .\"
-.TH "BSPWM" "1" "09/08/2017" "Bspwm 0\&.9\&.3\-26\-g412da35" "Bspwm Manual"
+.TH "BSPWM" "1" "09/29/2017" "Bspwm 0\&.9\&.3\-30\-gd953f6f" "Bspwm Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -1089,7 +1089,7 @@ Prefix prepended to each of the status lines\&.
 .PP
 \fIexternal_rules_command\fR
 .RS 4
-External command used to retrieve rule consequences\&. The command will receive the following arguments: window ID, class and instance names, monitor, desktop and node selectors\&. The output of that command must have the following format:
+External command used to retrieve rule consequences\&. The command will receive the following arguments: window ID, class name, instance name, and intermediate consequences\&. The output of that command must have the following format:
 \fBkey1=value1 key2=value2 \&...\fR
 (the valid key/value pairs are given in the description of the
 \fIrule\fR
index abd84c77d5bf8784b1992f99618c4d392d05e68b..bd0605f8f998e698cdf1736bdacd942768dcd11e 100644 (file)
@@ -646,7 +646,7 @@ Global Settings
        Prefix prepended to each of the status lines.
 
 'external_rules_command'::
-       External command used to retrieve rule consequences. The command will receive the following arguments: window ID, class and instance names, monitor, desktop and node selectors. The output of that command must have the following format: *key1=value1 key2=value2 ...* (the valid key/value pairs are given in the description of the 'rule' command).
+       External command used to retrieve rule consequences. The command will receive the following arguments: window ID, class name, instance name, and intermediate consequences. The output of that command must have the following format: *key1=value1 key2=value2 ...* (the valid key/value pairs are given in the description of the 'rule' command).
 
 'initial_polarity'::
        On which child should a new window be attached when adding a window on a single window tree in automatic mode. Accept the following values: *first_child*, *second_child*.
index b4e79a64a4ec4f72267de87858d1c1ea9d5ea1d6..85b175ef072d45593ac4be89c32ab91f33c5fd8b 100644 (file)
@@ -150,6 +150,39 @@ char *mktempfifo(const char *template)
        return fifo_path;
 }
 
+int asprintf(char **buf, const char *fmt, ...)
+{
+       int size = 0;
+       va_list args;
+       va_start(args, fmt);
+       size = vasprintf(buf, fmt, args);
+       va_end(args);
+       return size;
+}
+
+int vasprintf(char **buf, const char *fmt, va_list args)
+{
+       int size = 0;
+
+       va_list tmp;
+       va_copy(tmp, args);
+       size = vsnprintf(NULL, size, fmt, tmp);
+       va_end(tmp);
+
+       if (size < 0) {
+               return -1;
+       }
+
+       *buf = malloc(size + 1);
+
+       if (*buf == NULL) {
+               return -1;
+       }
+
+       size = vsprintf(*buf, fmt, args);
+       return size;
+}
+
 /* Adapted from i3wm */
 uint32_t get_color_pixel(const char *color)
 {
index ff776427e2c4f4375dc9ba7559dc918058141369..82bad85e06aaf784af69e3e7fc5a47127ecaf872 100644 (file)
@@ -79,7 +79,9 @@ void warn(char *fmt, ...);
 void err(char *fmt, ...);
 char *read_string(const char *file_path, size_t *tlen);
 char *copy_string(char *str, size_t len);
-char *mktempfifo(const char *template) ;
+char *mktempfifo(const char *template);
+int asprintf(char **buf, const char *fmt, ...);
+int vasprintf(char **buf, const char *fmt, va_list args);
 uint32_t get_color_pixel(const char *color);
 bool is_hex_color(const char *color);
 
index 30ee021fb3d43d1bb8c8068ac86a61360be2e79e..950226a272851df750a28e0110d131b269f539cc 100644 (file)
@@ -383,6 +383,32 @@ void print_pointer_action(pointer_action_t a, FILE *rsp)
        }
 }
 
+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 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,
+               ON_OFF_STR(csq->hidden), ON_OFF_STR(csq->sticky), ON_OFF_STR(csq->private),
+               ON_OFF_STR(csq->locked), 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);
+}
+
+void print_rectangle(char **buf, xcb_rectangle_t *rect)
+{
+       if (rect != NULL) {
+               asprintf(buf, "%hux%hu+%hi+%hi", rect->width, rect->height, rect->x, rect->y);
+       }
+}
+
 node_select_t make_node_select(void)
 {
        node_select_t sel = {
index b26ddf6798c9c602623986006c8c5bdb4e364df6..024c58733442683b7f6b9625572e2f3940c62d2c 100644 (file)
@@ -67,6 +67,8 @@ void fprint_desktop_name(desktop_t *d, 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 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);
 desktop_select_t make_desktop_select(void);
 monitor_select_t make_monitor_select(void);
index 729e2ef5950d6a4a216a9f351198c85ec2a4f023..e3e9778f1171717ec6d1b2bdfef40d1258fdd6dc 100644 (file)
@@ -31,6 +31,7 @@
 #include "bspwm.h"
 #include "ewmh.h"
 #include "window.h"
+#include "query.h"
 #include "parse.h"
 #include "settings.h"
 #include "rule.h"
@@ -305,9 +306,12 @@ bool schedule_rules(xcb_window_t win, rule_consequence_t *csq)
                dup2(fds[1], 1);
                close(fds[0]);
                char wid[SMALEN];
+               char *csq_buf;
+               print_rule_consequence(&csq_buf, csq);
                snprintf(wid, sizeof(wid), "%i", win);
                setsid();
-               execl(external_rules_command, external_rules_command, wid, csq->class_name, csq->instance_name, csq->monitor_desc, csq->desktop_desc, csq->node_desc, NULL);
+               execl(external_rules_command, external_rules_command, wid, csq->class_name, csq->instance_name, csq_buf, NULL);
+               free(csq_buf);
                err("Couldn't spawn rule command.\n");
        } else if (pid > 0) {
                close(fds[1]);