]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/child.c
Merge branch 'hide' into next
[i3/i3] / i3bar / src / child.c
index b14f873bfc329c7a4e3519f60bb3ca88c5f50068..2ba839ecd121a0232ea28dbbe8ff818caa7d4289 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * i3bar - an xcb-based status- and ws-bar for i3
+ *
+ * © 2010 Axel Wagner and contributors
+ *
+ * See file LICNSE for license information
+ *
+ * src/child.c: Getting Input for the statusline
+ *
+ */
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -27,38 +37,8 @@ void cleanup() {
 }
 
 /*
- * Since we don't use colors and stuff, we strip the dzen-formatstrings
- *
- */
-void strip_dzen_formats(char *buffer) {
-    char *src = buffer;
-    char *dest = buffer;
-    while (*src != '\0') {
-        /* ^ starts a format-string, ) ends it */
-        if (*src == '^') {
-            /* We replace the seperators from i3status by pipe-symbols */
-            if (!strncmp(src, "^ro", strlen("^ro"))) {
-                *(dest++) = ' ';
-                *(dest++) = '|';
-                *(dest++) = ' ';
-            }
-            while (*src != ')') {
-                src++;
-            }
-            src++;
-        } else {
-            *dest = *src;
-            src++;
-            dest++;
-        }
-    }
-    /* The last character is \n, which xcb cannot display */
-    *(--dest) = '\0';
-}
-
-/*
- * Callbalk for stdin. We read a line from stdin, strip dzen-formats and store
- * the result in statusline
+ * Callbalk for stdin. We read a line from stdin and store the result
+ * in statusline
  *
  */
 void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
@@ -72,6 +52,8 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
         n = read(fd, buffer + rec, buffer_len - rec);
         if (n == -1) {
             if (errno == EAGAIN) {
+                /* remove trailing newline and finish up */
+                buffer[rec-1] = '\0';
                 break;
             }
             printf("ERROR: read() failed!");
@@ -86,6 +68,8 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
                 buffer_len += STDIN_CHUNK_SIZE;
                 FREE(tmp);
             } else {
+                /* remove trailing newline and finish up */
+                buffer[rec-1] = '\0';
                 break;
             }
         }
@@ -95,7 +79,6 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
         FREE(buffer);
         return;
     }
-    strip_dzen_formats(buffer);
     FREE(statusline);
     statusline = buffer;
     printf("%s\n", buffer);
@@ -166,7 +149,7 @@ void start_child(char *command) {
 }
 
 /*
- * kill()s the child-prozess (if existend) and closes and
+ * kill()s the child-process (if existent) and closes and
  * free()s the stdin- and sigchild-watchers
  *
  */
@@ -176,3 +159,23 @@ void kill_child() {
     }
     cleanup();
 }
+
+/*
+ * Sends a SIGSTOP to the child-process (if existent)
+ *
+ */
+void stop_child() {
+    if (child_pid != 0) {
+        kill(child_pid, SIGSTOP);
+    }
+}
+
+/*
+ * Sends a SIGCONT to the child-process (if existent)
+ *
+ */
+void cont_child() {
+    if (child_pid != 0) {
+        kill(child_pid, SIGCONT);
+    }
+}