]> git.lizzy.rs Git - bspwm.git/commitdiff
Add an option to *subscribe*: --count
authorBastien Dejean <nihilhill@gmail.com>
Sat, 22 Jul 2017 14:55:31 +0000 (16:55 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Sat, 22 Jul 2017 14:55:31 +0000 (16:55 +0200)
doc/bspwm.1
doc/bspwm.1.asciidoc
src/messages.c
src/subscribe.c
src/subscribe.h
src/types.h

index cd7dc6b523b6eb105f12ebbcc123f6f9f4be7fa2..f3558b00e4745c9fa99809317cdc1766c6dd7112 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: 07/14/2017
+.\"      Date: 07/22/2017
 .\"    Manual: Bspwm Manual
-.\"    Source: Bspwm 0.9.3
+.\"    Source: Bspwm 0.9.3-1-g0ae3c57
 .\"  Language: English
 .\"
-.TH "BSPWM" "1" "07/14/2017" "Bspwm 0\&.9\&.3" "Bspwm Manual"
+.TH "BSPWM" "1" "07/22/2017" "Bspwm 0\&.9\&.3\-1\-g0ae3c57" "Bspwm Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -973,11 +973,15 @@ Get or set the value of <setting>\&.
 \fBGeneral Syntax\fR
 .RS 4
 .PP
-subscribe (all|report|monitor|desktop|node|\&...)*
+subscribe [\-c|\-\-count \fICOUNT\fR] (all|report|monitor|desktop|node|\&...)*
 .RS 4
 Continuously print status information\&. See the
 \fBEVENTS\fR
-section for the detailed description of each event\&.
+section for the detailed description of each event\&. If a
+\fICOUNT\fR
+argument is provided, then the subscriber will return after having received
+\fICOUNT\fR
+events\&.
 .RE
 .RE
 .SS "Quit"
index ff8031e476b29d4d78f4705cb69c4336e76bddb6..336b3ad00ae8178339930306435fd816ae0ea183 100644 (file)
@@ -574,8 +574,8 @@ Subscribe
 
 General Syntax
 ^^^^^^^^^^^^^^
-subscribe (all|report|monitor|desktop|node|...)*::
-       Continuously print status information. See the *EVENTS* section for the detailed description of each event.
+subscribe [-c|--count 'COUNT'] (all|report|monitor|desktop|node|...)*::
+       Continuously print status information. See the *EVENTS* section for the detailed description of each event. If a 'COUNT' argument is provided, then the subscriber will return after having received 'COUNT' events.
 
 Quit
 ~~~~
index 7706bd073112d40a686bc50a497d27ef35966b96..412204350e4e4162e732050742fb0ff2096f71fb 100644 (file)
@@ -1213,12 +1213,24 @@ void cmd_wm(char **args, int num, FILE *rsp)
 int cmd_subscribe(char **args, int num, FILE *rsp)
 {
        int field = 0;
+       int count = -1;
+
        if (num < 1) {
                field = SBSC_MASK_REPORT;
        } else {
                subscriber_mask_t mask;
                while (num > 0) {
-                       if (parse_subscriber_mask(*args, &mask)) {
+                       if (streq("-c", *args) || streq("--count", *args)) {
+                               num--, args++;
+                               if (num < 1) {
+                                       fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
+                                       return SUBSCRIBE_FAILURE;
+                               }
+                               if (sscanf(*args, "%i", &count) != 1) {
+                                       fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
+                                       return SUBSCRIBE_FAILURE;
+                               }
+                       } else if (parse_subscriber_mask(*args, &mask)) {
                                field |= mask;
                        } else {
                                fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
@@ -1228,7 +1240,7 @@ int cmd_subscribe(char **args, int num, FILE *rsp)
                }
        }
 
-       add_subscriber(rsp, field);
+       add_subscriber(rsp, field, count);
        return SUBSCRIBE_SUCCESS;
 }
 
index 8a0b2a14dfca894ec94370fca8525da94dcbb908..4a8c961eeb6a757ca551eb285c4135c428a6bf4e 100644 (file)
 #include "settings.h"
 #include "subscribe.h"
 
-subscriber_list_t *make_subscriber_list(FILE *stream, int field)
+subscriber_list_t *make_subscriber_list(FILE *stream, int field, int count)
 {
        subscriber_list_t *sb = calloc(1, sizeof(subscriber_list_t));
        sb->prev = sb->next = NULL;
        sb->stream = stream;
        sb->field = field;
+       sb->count = count;
        return sb;
 }
 
@@ -63,9 +64,9 @@ void remove_subscriber(subscriber_list_t *sb)
        free(sb);
 }
 
-void add_subscriber(FILE *stream, int field)
+void add_subscriber(FILE *stream, int field, int count)
 {
-       subscriber_list_t *sb = make_subscriber_list(stream, field);
+       subscriber_list_t *sb = make_subscriber_list(stream, field, count);
        if (subscribe_head == NULL) {
                subscribe_head = subscribe_tail = sb;
        } else {
@@ -129,6 +130,9 @@ void put_status(subscriber_mask_t mask, ...)
        while (sb != NULL) {
                subscriber_list_t *next = sb->next;
                if (sb->field & mask) {
+                       if (sb->count > 0) {
+                               sb->count--;
+                       }
                        if (mask == SBSC_MASK_REPORT) {
                                ret = print_report(sb->stream);
                        } else {
@@ -140,7 +144,7 @@ void put_status(subscriber_mask_t mask, ...)
                                va_end(args);
                                ret = fflush(sb->stream);
                        }
-                       if (ret != 0) {
+                       if (ret != 0 || sb->count == 0) {
                                remove_subscriber(sb);
                        }
                }
index 496ce8dfb698ba3d782b4772cd957cedc3bf95da..26771be0e38a2deff670a4ef243453fadcc114a8 100644 (file)
@@ -60,9 +60,9 @@ typedef enum {
        SBSC_MASK_ALL = (1 << 28) - 1
 } subscriber_mask_t;
 
-subscriber_list_t *make_subscriber_list(FILE *stream, int field);
+subscriber_list_t *make_subscriber_list(FILE *stream, int field, int count);
 void remove_subscriber(subscriber_list_t *sb);
-void add_subscriber(FILE *stream, int field);
+void add_subscriber(FILE *stream, int field, int count);
 int print_report(FILE *stream);
 void put_status(subscriber_mask_t mask, ...);
 
index f017521818c3f0bf6acb870a061b9e0d95a8557a..3321c0838bb3eb93a4d4c6169b879a848f75ace0 100644 (file)
@@ -304,6 +304,7 @@ struct subscriber_list_t {
        int fd;
        FILE *stream;
        int field;
+       int count;
        subscriber_list_t *prev;
        subscriber_list_t *next;
 };