]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/ipc.c
i3bar: Allow to force unhide with draw_bars
[i3/i3] / i3bar / src / ipc.c
index db60a3620960bd0aa7f00fb6482be8bede8c8ffb..fc8c6492d9b9759211142aa7450740ddf1225e5d 100644 (file)
@@ -2,12 +2,9 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3bar - an xcb-based status- and ws-bar for i3
+ * © 2010-2012 Axel Wagner and contributors (see also: LICENSE)
  *
- * © 2010-2011 Axel Wagner and contributors
- *
- * See file LICNSE for license information
- *
- * src/ipc.c: Communicating with i3
+ * ipc.c: Communicating with i3
  *
  */
 #include <stdlib.h>
@@ -45,7 +42,7 @@ void got_command_reply(char *reply) {
 void got_workspace_reply(char *reply) {
     DLOG("Got Workspace-Data!\n");
     parse_workspaces_json(reply);
-    draw_bars();
+    draw_bars(false);
 }
 
 /*
@@ -68,6 +65,13 @@ void got_output_reply(char *reply) {
     DLOG("Reconfiguring Windows...\n");
     realloc_sl_buffer();
     reconfig_windows();
+
+    i3_output *o_walk;
+    SLIST_FOREACH(o_walk, outputs, slist) {
+        kick_tray_clients(o_walk);
+    }
+
+    draw_bars(false);
 }
 
 /*
@@ -150,11 +154,7 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
 
     /* First we only read the header, because we know its length */
     uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2;
-    char *header = malloc(header_len);
-    if (header == NULL) {
-        ELOG("Could not allocate memory: %s\n", strerror(errno));
-        exit(EXIT_FAILURE);
-    }
+    char *header = smalloc(header_len);
 
     /* We first parse the fixed-length IPC-header, to know, how much data
      * we have to expect */
@@ -169,6 +169,7 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
             /* EOF received. Since i3 will restart i3bar instances as appropriate,
              * we exit here. */
             DLOG("EOF received, exiting...\n");
+            clean_xcb();
             exit(EXIT_SUCCESS);
         }
         rec += n;
@@ -191,13 +192,7 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
 
     /* Now that we know, what to expect, we can start read()ing the rest
      * of the message */
-    char *buffer = malloc(size + 1);
-    if (buffer == NULL) {
-        /* EOF received. Since i3 will restart i3bar instances as appropriate,
-         * we exit here. */
-        DLOG("EOF received, exiting...\n");
-        exit(EXIT_SUCCESS);
-    }
+    char *buffer = smalloc(size + 1);
     rec = 0;
 
     while (rec < size) {
@@ -243,12 +238,7 @@ int i3_send_msg(uint32_t type, const char *payload) {
     /* TODO: I'm not entirely sure if this buffer really has to contain more
      * than the pure header (why not just write() the payload from *payload?),
      * but we leave it for now */
-    char *buffer = malloc(to_write);
-    if (buffer == NULL) {
-        ELOG("Could not allocate memory: %s\n", strerror(errno));
-        exit(EXIT_FAILURE);
-    }
-
+    char *buffer = smalloc(to_write);
     char *walk = buffer;
 
     strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC));
@@ -286,26 +276,8 @@ int i3_send_msg(uint32_t type, const char *payload) {
  */
 int init_connection(const char *socket_path) {
     sock_path = socket_path;
-    int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
-    if (sockfd == -1) {
-        ELOG("Could not create Socket: %s\n", strerror(errno));
-        exit(EXIT_FAILURE);
-    }
-
-    struct sockaddr_un addr;
-    memset(&addr, 0, sizeof(struct sockaddr_un));
-    addr.sun_family = AF_LOCAL;
-    strcpy(addr.sun_path, sock_path);
-    if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) {
-        ELOG("Could not connect to i3! %s: %s\n", sock_path, strerror(errno));
-        exit(EXIT_FAILURE);
-    }
-
-    i3_connection = malloc(sizeof(ev_io));
-    if (i3_connection == NULL) {
-        ELOG("malloc() failed: %s\n", strerror(errno));
-        exit(EXIT_FAILURE);
-    }
+    int sockfd = ipc_connect(socket_path);
+    i3_connection = smalloc(sizeof(ev_io));
     ev_io_init(i3_connection, &got_data, sockfd, EV_READ);
     ev_io_start(main_loop, i3_connection);
     return 1;
@@ -314,7 +286,7 @@ int init_connection(const char *socket_path) {
 /*
  * Destroy the connection to i3.
  */
-void destroy_connection() {
+void destroy_connection(void) {
     close(i3_connection->fd);
     ev_io_stop(main_loop, i3_connection);
 }
@@ -323,7 +295,7 @@ void destroy_connection() {
  * Subscribe to all the i3-events, we need
  *
  */
-void subscribe_events() {
+void subscribe_events(void) {
     if (config.disable_ws) {
         i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"output\" ]");
     } else {