Commits

William Giokas committed faa1c72

Rewrite of status printing

Most of this by numeral <ofear.balas@gmail.com>

  • Participants
  • Parent commits 0f99ac9
  • Branches master

Comments (0)

Files changed (3)

  * systemd has some new naming conventions you can turn on with longer names.
  */
 #define NET_DEVICE_PRIMARY "wlp3s0"
-/* Currently not of any use 
-#define NET_DEVICE_SECONDARY "enp0s25" */
+/* Currently not of any use */
+#define NET_DEVICE_SECONDARY "enp0s25"
 
 /* Specity path to your battery */
 #define BATT_PATH "/sys/class/power_supply/BAT0"
     char *time = NULL;
     char *batt = NULL;
     char *net = NULL;
+    char *net_sec = NULL;
     char *temp = NULL;
     char *ipaddr = NULL;
+    char *ipaddr_sec = NULL;
+
+#ifdef NET_DEVICE_PRIMARY
     char *net_device_up = NET_DEVICE_PRIMARY;
+#endif
+#ifdef NET_DEVICE_SECONDARY
+    char *net_device_sec = NET_DEVICE_SECONDARY;
+#endif
+
     time_t count60 = 0;
     time_t count10 = 0;
 
         }
         /* Update every 10 seconds */
         if (runevery(&count10, 10)) {
+#ifdef BATT_PATH
+            free(batt);
+            batt = getbattery(BATT_PATH);
+#endif
+#ifdef TEMP_SENSOR_PATH
+#ifdef TEMP_SENSOR_UNIT
             free(avgs);
             free(temp);
-            free(batt);
 
             avgs   = loadavg();
             temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
-            batt   = getbattery(BATT_PATH);
             SFREE(temp);
+#endif
+#endif
         }
         /* Update every second */
+#ifdef NET_DEVICE_PRIMARY
         net    = get_netusage(net_device_up);
         ipaddr = get_ip_addr(net_device_up);
+#endif
+#ifdef NET_DEVICE_SECONDARY
+        net_sec = get_netusage(net_device_sec);
+        ipaddr_sec = get_ip_addr(net_device_sec);
+#endif
 
         /* Format of display */
-        status = smprintf("%s (%s) | %s [%s] T %s | %s",
-                net, ipaddr, batt, avgs, temp, time);
+        status = smprintf("%s%s%s%s%s%s",
+            ipaddr      == NULL ? "" : smprintf(" %s (%s) |", net, ipaddr),
+            ipaddr_sec  == NULL ? "" : smprintf(" %s (%s) |", net_sec, ipaddr_sec),
+            batt        == NULL ? "" : smprintf(" %s", batt),
+            avgs        == NULL ? "" : smprintf(" [%s]", avgs),
+            time        == NULL ? "" : smprintf(" %s", temp),
+            time        == NULL ? "" : smprintf(" | %s", time)
+            );
         SFREE(ipaddr)
         free(net);
+        SFREE(ipaddr_sec)
+        free(net_sec);
 
         if(tostatusbar == 0)
             setstatus(status);

include/network.h

 char *
 get_ip_addr(const char *interface)
 {
-    static char part[512];
+    static char part[100];
     socklen_t len = sizeof(struct sockaddr_in);
     memset(part, 0, sizeof(part));
     struct ifaddrs *ifaddr, *addrp;
 
         if (addrp == NULL) {
                 freeifaddrs(ifaddr);
-                return (found ? "no IP" : NULL);
+                return (found ? NULL : NULL);
             }
 
         int ret;
             fprintf(stderr, "dwmstatus: getnameinfo(): %s\n",
                 gai_strerror(ret));
             freeifaddrs(ifaddr);
-            return "no IP";
+            return NULL;
         }
     freeifaddrs(ifaddr);
     return part;