.\" 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
.\" -----------------------------------------------------------------
\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"
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
~~~~
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);
}
}
- add_subscriber(rsp, field);
+ add_subscriber(rsp, field, count);
return SUBSCRIBE_SUCCESS;
}
#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;
}
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 {
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 {
va_end(args);
ret = fflush(sb->stream);
}
- if (ret != 0) {
+ if (ret != 0 || sb->count == 0) {
remove_subscriber(sb);
}
}
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, ...);
int fd;
FILE *stream;
int field;
+ int count;
subscriber_list_t *prev;
subscriber_list_t *next;
};