]> git.lizzy.rs Git - bspwm.git/commitdiff
Use specified fifo ('-s' flag) instead of stdout
authorBastien Dejean <nihilhill@gmail.com>
Tue, 18 Dec 2012 11:38:46 +0000 (12:38 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Tue, 18 Dec 2012 11:38:46 +0000 (12:38 +0100)
Makefile
README.md
bspwm.1
bspwm.c
bspwm.h
tree.c

index 0c721005b1f8c4d5e1da1a81b6db002d8bca2c62..196871bd605ca4f8b43b4fb792945ecd70af8eba 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ options:
 
 .c.o:
        @echo "CC $<"
-       @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
+       @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -D_POSIX_C_SOURCE="2" -c -o $@ $<
 
 bspwm: $(WM_OBJ)
        @echo CC -o $@
index 6879f6917d74320e3f2551c0fafbc313e41875c0..39c9e0481fb5e31df03536dfe95afedd315a70aa 100644 (file)
--- a/README.md
+++ b/README.md
@@ -65,6 +65,12 @@ was sent beforehand:
         |            |            |         |            |            |
         +-------------------------+         +-------------------------+
 
+## Synopsis
+
+    bspwm [-v|-s STATUS_FIFO]
+
+    bspc MESSAGE [ARGUMENTS] [OPTIONS]
+
 ## Messages
 
 The syntax for the client is `bspc MESSAGE [ARGUMENTS ...]`.
@@ -272,9 +278,6 @@ Colors are either [X color names](http://en.wikipedia.org/wiki/X11_color_names)
     adaptative_raise
         Prevent floating windows from being raised when they might cover other floating windows.
 
-    status_stdout
-        Output the status of monitors and desktops on stdout.
-
 ## Mouse Bindings
 
     button_modifier + left mouse button
diff --git a/bspwm.1 b/bspwm.1
index e38c47c85dcc7dc00a08489e9dc77c7827721bb7..3150dd9d66b53651e6ac0804c7d045a315904e12 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -2,8 +2,8 @@
 .SH NAME
 bspwm \- Tiling window manager based on binary space partitioning
 .SH SYNOPSIS
-.BI bspwm
-.RI [ -v ]
+.B bspwm
+.RI [ -v | "-s STATUS_FIFO" ]
 .P
 .BI bspc " MESSAGE"
 .RI [ ARGUMENTS ]
@@ -311,9 +311,6 @@ Wether to focus the window under the mouse pointer.
 .TP
 .I adaptative_raise
 Prevent floating windows from being raised when they might cover other floating windows.
-.TP
-.I status_stdout
-Output the status of monitors and desktops on stdout.
 .SH MOUSE BINDINGS
 .TP
 .I button_modifier + left mouse button
diff --git a/bspwm.c b/bspwm.c
index 6828bb66c3860818c6fb5fd67550b815fc3649fe..87155d3e6c3f6e0f0bd7b9e240f02022c61b8242 100644 (file)
--- a/bspwm.c
+++ b/bspwm.c
@@ -141,23 +141,30 @@ void setup(void)
 
 int main(int argc, char *argv[])
 {
-    if (argc == 2 && strcmp(argv[1], "-v") == 0) {
-        printf("%s\n", VERSION);
-        exit(EXIT_SUCCESS);
-    }
-
     fd_set descriptors;
     char socket_path[MAXLEN];
+    char *fifo_path = NULL;
     int sock_fd, ret_fd, dpy_fd, sel, n;
     struct sockaddr_un sock_address;
     size_t rsplen = 0;
     char msg[BUFSIZ] = {0};
     char rsp[BUFSIZ] = {0};
-
     xcb_generic_event_t *event;
+    char opt;
+
+    while ((opt = getopt(argc, argv, "vs:")) != -1) {
+        switch (opt) {
+            case 'v':
+                printf("%s\n", VERSION);
+                exit(EXIT_SUCCESS);
+                break;
+            case 's':
+                fifo_path = optarg;
+                break;
+        }
+    }
 
     running = true;
-
     dpy = xcb_connect(NULL, &default_screen);
 
     if (xcb_connection_has_error(dpy))
@@ -181,9 +188,16 @@ int main(int argc, char *argv[])
 
     bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address));
     listen(sock_fd, SOMAXCONN);
-
     sel = MAX(sock_fd, dpy_fd) + 1;
 
+    if (fifo_path != NULL) {
+        int fifo_fd = open(fifo_path, O_RDWR | O_NONBLOCK);
+        if (fifo_fd != -1)
+            status_fifo = fdopen(fifo_fd, "w");
+        else
+            warn("couldn't open status fifo\n");
+    }
+
     load_settings();
     run_autostart();
     grab_buttons();
@@ -228,6 +242,8 @@ int main(int argc, char *argv[])
     }
 
     close(sock_fd);
+    if (status_fifo != NULL)
+        fclose(status_fifo);
     xcb_ewmh_connection_wipe(ewmh);
     free(ewmh);
     xcb_flush(dpy);
diff --git a/bspwm.h b/bspwm.h
index d1600bbe25cd14b210d5ba013906cfde73fdab98..261e8d99a837b685105128e6c6177cb464752f38 100644 (file)
--- a/bspwm.h
+++ b/bspwm.h
@@ -16,6 +16,7 @@ unsigned int desktop_uid;
 unsigned int client_uid;
 xcb_screen_t *screen;
 uint8_t root_depth;
+FILE *status_fifo;
 
 split_mode_t split_mode;
 direction_t split_dir;
diff --git a/tree.c b/tree.c
index b0743e2205cbd9cbb357cdd816c921901ab66d46..a350784c4705da94ce59f98156671c6ae7af124d 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -228,19 +228,19 @@ void list_desktops(monitor_t *m, list_option_t opt, unsigned int depth, char *rs
 
 void put_status(void)
 {
-    if (!status_stdout)
+    if (status_fifo == NULL)
         return;
     bool urgent = false;
     for (monitor_t *m = mon_head; m != NULL; m = m->next) {
-        printf("%c%s:", (mon == m ? 'M' : 'm'), m->name);
+        fprintf(status_fifo, "%c%s:", (mon == m ? 'M' : 'm'), m->name);
         for (desktop_t *d = m->desk_head; d != NULL; d = d->next, urgent = false) {
             for (node_t *n = first_extrema(d->root); n != NULL && !urgent; n = next_leaf(n))
                 urgent |= n->client->urgent;
-            printf("%c%c%s:", (m->desk == d ? 'D' : (d->root != NULL ? 'd' : '_')), (urgent ? '!' : '_'), d->name);
+            fprintf(status_fifo, "%c%c%s:", (m->desk == d ? 'D' : (d->root != NULL ? 'd' : '_')), (urgent ? '!' : '_'), d->name);
         }
     }
-    printf("L%s:W%X\n", (mon->desk->layout == LAYOUT_TILED ? "tiled" : "monocle"), (mon->desk->focus == NULL ? 0 : mon->desk->focus->client->window));
-    fflush(stdout);
+    fprintf(status_fifo, "L%s:W%X\n", (mon->desk->layout == LAYOUT_TILED ? "tiled" : "monocle"), (mon->desk->focus == NULL ? 0 : mon->desk->focus->client->window));
+    fflush(status_fifo);
 }
 
 void arrange(monitor_t *m, desktop_t *d)