.\" Title: bspwm
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\" Date: 07/23/2017
+.\" Date: 07/24/2017
.\" Manual: Bspwm Manual
-.\" Source: Bspwm 0.9.3-7-gc968f7a
+.\" Source: Bspwm 0.9.3-9-g9ce48c4
.\" Language: English
.\"
-.TH "BSPWM" "1" "07/23/2017" "Bspwm 0\&.9\&.3\-7\-gc968f7a" "Bspwm Manual"
+.TH "BSPWM" "1" "07/24/2017" "Bspwm 0\&.9\&.3\-9\-g9ce48c4" "Bspwm Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.PP
subscribe [\fIOPTIONS\fR] (all|report|monitor|desktop|node|\&...)*
.RS 4
-Continuously print status information\&. See the
+Continuously print events\&. See the
\fBEVENTS\fR
-section for the detailed description of each event\&.
+section for the description of each event\&.
.RE
.RE
.sp
\fBOptions\fR
.RS 4
.PP
+\fB\-f\fR, \fB\-\-fifo\fR
+.RS 4
+Print a path to a FIFO from which events can be read and return\&.
+.RE
+.PP
\fB\-c\fR, \fB\-\-count\fR \fICOUNT\fR
.RS 4
Stop the corresponding
General Syntax
^^^^^^^^^^^^^^
subscribe ['OPTIONS'] (all|report|monitor|desktop|node|...)*::
- Continuously print status information. See the *EVENTS* section for the detailed description of each event.
+ Continuously print events. See the *EVENTS* section for the description of each event.
Options
^^^^^^^
+*-f*, *--fifo*::
+ Print a path to a FIFO from which events can be read and return.
+
*-c*, *--count* 'COUNT'::
Stop the corresponding *bspc* process after having received 'COUNT' events.
return cpy;
}
+char *mktempfifo(const char *template)
+{
+ char *fifo_path = malloc(strlen(template)+1);
+ if (fifo_path == NULL) {
+ return NULL;
+ }
+ sprintf(fifo_path, "%s", template);
+ if (mktemp(fifo_path) == NULL) {
+ free(fifo_path);
+ return NULL;
+ }
+ if (mkfifo(fifo_path, 0666) == -1) {
+ free(fifo_path);
+ return NULL;
+ }
+ return fifo_path;
+}
+
/* Adapted from i3wm */
uint32_t get_color_pixel(const char *color)
{
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) ;
uint32_t get_color_pixel(const char *color);
bool is_hex_color(const char *color);
fflush(rsp);
- if (ret != SUBSCRIBE_SUCCESS) {
+ if (ret != SUBSCRIBE_SOCKET) {
fclose(rsp);
}
}
{
int field = 0;
int count = -1;
+ FILE *stream = rsp;
+ char *fifo_path = NULL;
if (num < 1) {
field = SBSC_MASK_REPORT;
fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
return SUBSCRIBE_FAILURE;
}
+ } else if (streq("-f", *args) || streq("--fifo", *args)) {
+ fifo_path = mktempfifo(FIFO_TEMPLATE);
+ if (fifo_path == NULL) {
+ fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
+ return SUBSCRIBE_FAILURE;
+ }
+ stream = NULL;
+ fprintf(rsp, "%s\n", fifo_path);
} else if (parse_subscriber_mask(*args, &mask)) {
field |= mask;
} else {
}
}
- add_subscriber(rsp, field, count);
- return SUBSCRIBE_SUCCESS;
+ add_subscriber(stream, fifo_path, field, count);
+
+ if (stream != NULL) {
+ return SUBSCRIBE_SOCKET;
+ } else {
+ return SUBSCRIBE_FIFO;
+ }
}
void cmd_quit(char **args, int num, FILE *rsp)
#include "subscribe.h"
enum {
- SUBSCRIBE_SUCCESS,
+ SUBSCRIBE_SOCKET,
+ SUBSCRIBE_FIFO,
SUBSCRIBE_FAILURE
};
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <ctype.h>
#include <stdarg.h>
#include "bspwm.h"
#include "settings.h"
#include "subscribe.h"
-subscriber_list_t *make_subscriber_list(FILE *stream, int field, int count)
+subscriber_list_t *make_subscriber_list(FILE *stream, char *fifo_path, int field, int count)
{
subscriber_list_t *sb = calloc(1, sizeof(subscriber_list_t));
sb->prev = sb->next = NULL;
sb->stream = stream;
+ sb->fifo_path = fifo_path;
sb->field = field;
sb->count = count;
return sb;
subscribe_tail = a;
}
fclose(sb->stream);
+ unlink(sb->fifo_path);
+ free(sb->fifo_path);
free(sb);
}
-void add_subscriber(FILE *stream, int field, int count)
+void add_subscriber(FILE *stream, char* fifo_path, int field, int count)
{
- subscriber_list_t *sb = make_subscriber_list(stream, field, count);
+ subscriber_list_t *sb = make_subscriber_list(stream, fifo_path, field, count);
if (subscribe_head == NULL) {
subscribe_head = subscribe_tail = sb;
} else {
if (sb->count > 0) {
sb->count--;
}
+ if (sb->stream == NULL) {
+ sb->stream = fopen(sb->fifo_path, "w");
+ }
if (mask == SBSC_MASK_REPORT) {
ret = print_report(sb->stream);
} else {
#ifndef BSPWM_SUBSCRIBE_H
#define BSPWM_SUBSCRIBE_H
+#define FIFO_TEMPLATE "/tmp/bspwm_fifo.XXXXX"
+
typedef enum {
SBSC_MASK_REPORT = 1 << 0,
SBSC_MASK_MONITOR_ADD = 1 << 1,
SBSC_MASK_ALL = (1 << 28) - 1
} subscriber_mask_t;
-subscriber_list_t *make_subscriber_list(FILE *stream, int field, int count);
+subscriber_list_t *make_subscriber_list(FILE *stream, char *fifo_path, int field, int count);
void remove_subscriber(subscriber_list_t *sb);
-void add_subscriber(FILE *stream, int field, int count);
+void add_subscriber(FILE *stream, char* fifo_path, int field, int count);
int print_report(FILE *stream);
void put_status(subscriber_mask_t mask, ...);
struct subscriber_list_t {
int fd;
FILE *stream;
+ char* fifo_path;
int field;
int count;
subscriber_list_t *prev;