mirror of
https://github.com/alrayyes/slstatus.git
synced 2024-11-21 11:06:23 +00:00
added combined_network
This commit is contained in:
parent
c66124061f
commit
ef39d1fb6d
3 changed files with 140 additions and 6 deletions
6
PKGBUILD
6
PKGBUILD
|
@ -15,6 +15,7 @@ _patches=(
|
|||
"backlight-20190305-85a4a18.diff"
|
||||
"ipv4-multiple-20190312-5f08c89.diff"
|
||||
"netspeed-multiple-20190312-2ac86e1.diff"
|
||||
"combined_network-20190312-619ed9f.diff"
|
||||
)
|
||||
|
||||
source=("git+https://git.suckless.org/${pkgname%-git}"
|
||||
|
@ -22,11 +23,12 @@ source=("git+https://git.suckless.org/${pkgname%-git}"
|
|||
"${_patches[@]}")
|
||||
|
||||
md5sums=('SKIP'
|
||||
'ed201d76de309678c72007413f4c7005'
|
||||
'5dcbe7ba6e38e1b6e545a58a44929dd8'
|
||||
'24ea93ef665decc0315248f62aa65f44'
|
||||
'58404d0af1893f560926daf605a79919'
|
||||
'fc9b31ea31470b6816f1f92c6bc6fa9d'
|
||||
'30f0a42ffc0e4f1e102ad2e3d1afe988')
|
||||
'30f0a42ffc0e4f1e102ad2e3d1afe988'
|
||||
'865b046340744bc08c52170e0be78355')
|
||||
|
||||
pkgver() {
|
||||
cd "${pkgname%-git}"
|
||||
|
|
131
combined_network-20190312-619ed9f.diff
Normal file
131
combined_network-20190312-619ed9f.diff
Normal file
|
@ -0,0 +1,131 @@
|
|||
From 619ed9f44fa7d1d263c687adf7b960153cc5c32f Mon Sep 17 00:00:00 2001
|
||||
From: Ryan Kes <alrayyes@gmail.com>
|
||||
Date: Tue, 12 Mar 2019 12:46:00 +0100
|
||||
Subject: [PATCH] Addec combined_network
|
||||
|
||||
---
|
||||
Makefile | 1 +
|
||||
components/combined_network.c | 84 +++++++++++++++++++++++++++++++++++
|
||||
slstatus.h | 3 ++
|
||||
3 files changed, 88 insertions(+)
|
||||
create mode 100644 components/combined_network.c
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
index c93032f..5fe36c2 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -8,6 +8,7 @@ REQ = util
|
||||
COM =\
|
||||
components/backlight\
|
||||
components/battery\
|
||||
+ components/combined_network\
|
||||
components/cpu\
|
||||
components/datetime\
|
||||
components/disk\
|
||||
diff --git a/components/combined_network.c b/components/combined_network.c
|
||||
new file mode 100644
|
||||
index 0000000..5e3087f
|
||||
--- /dev/null
|
||||
+++ b/components/combined_network.c
|
||||
@@ -0,0 +1,84 @@
|
||||
+/* See LICENSE file for copyright and license details. */
|
||||
+#include <stdio.h>
|
||||
+#include <string.h>
|
||||
+
|
||||
+#include "../util.h"
|
||||
+#include "../slstatus.h"
|
||||
+
|
||||
+#if defined(__linux__)
|
||||
+ #include <limits.h>
|
||||
+ #include <stdint.h>
|
||||
+ #include <unistd.h>
|
||||
+
|
||||
+ /**
|
||||
+ * Incredibly hacky and nasty, but i'm lazy and don't want to put too much time into this. regular wifi_perc causes havoc because of returning string
|
||||
+ */
|
||||
+ const int *
|
||||
+ combined_wifi_perc(const char *interface)
|
||||
+ {
|
||||
+ int cur;
|
||||
+ size_t i;
|
||||
+ char *p, *datastart;
|
||||
+ char path[PATH_MAX];
|
||||
+ char status[5];
|
||||
+ FILE *fp;
|
||||
+
|
||||
+ if (esnprintf(path, sizeof(path), "/sys/class/net/%s/operstate",
|
||||
+ interface) < 0) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ if (!(fp = fopen(path, "r"))) {
|
||||
+ warn("fopen '%s':", path);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ p = fgets(status, 5, fp);
|
||||
+ fclose(fp);
|
||||
+ if (!p || strcmp(status, "up\n") != 0) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (!(fp = fopen("/proc/net/wireless", "r"))) {
|
||||
+ warn("fopen '/proc/net/wireless':");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < 3; i++) {
|
||||
+ if (!(p = fgets(buf, sizeof(buf) - 1, fp)))
|
||||
+ break;
|
||||
+ }
|
||||
+ fclose(fp);
|
||||
+ if (i < 2 || !p) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (!(datastart = strstr(buf, interface))) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ datastart = (datastart+(strlen(interface)+1));
|
||||
+ sscanf(datastart + 1, " %*d %d %*d %*d\t\t %*d\t "
|
||||
+ "%*d\t\t%*d\t\t %*d\t %*d\t\t %*d", &cur);
|
||||
+
|
||||
+ /* 70 is the max of /proc/net/wireless */
|
||||
+ return (int)((float)cur / 70 * 100);
|
||||
+ }
|
||||
+
|
||||
+ const char *
|
||||
+ combined_network()
|
||||
+ {
|
||||
+ if (ipv4("wlp4s0"))
|
||||
+ return bprintf("%s %s %d%% ", "", wifi_essid("wlp4s0"), combined_wifi_perc("wlp4s0"));
|
||||
+ else if (ipv4("enp0s31f6"))
|
||||
+ return bprintf(" eth0 ");
|
||||
+
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+#else
|
||||
+ const char *
|
||||
+ combined_network()
|
||||
+ {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+#endif
|
||||
diff --git a/slstatus.h b/slstatus.h
|
||||
index aaaec9e..a91b796 100644
|
||||
--- a/slstatus.h
|
||||
+++ b/slstatus.h
|
||||
@@ -8,6 +8,9 @@ const char *battery_perc(const char *);
|
||||
const char *battery_state(const char *);
|
||||
const char *battery_remaining(const char *);
|
||||
|
||||
+/* combined netowrk */
|
||||
+const char *combined_network(void);
|
||||
+
|
||||
/* cpu */
|
||||
const char *cpu_freq(void);
|
||||
const char *cpu_perc(void);
|
||||
--
|
||||
2.21.0
|
||||
|
9
config.h
9
config.h
|
@ -17,7 +17,7 @@ static const char unknown_str[] = "n/a";
|
|||
* battery_state battery charging state battery name (BAT0)
|
||||
* NULL on OpenBSD
|
||||
* battery_remaining battery remaining HH:MM battery name (BAT0)
|
||||
* NULL on OpenBSD
|
||||
* combined_network Combined interface data NULL
|
||||
* cpu_perc cpu usage in percent NULL
|
||||
* cpu_freq cpu frequency in MHz NULL
|
||||
* datetime date and time format string (%F %T)
|
||||
|
@ -65,8 +65,9 @@ static const char unknown_str[] = "n/a";
|
|||
static const struct arg args[] = {
|
||||
/* function format argument */
|
||||
/* { seperator, "\x05", NULL }, */
|
||||
{ wifi_essid, "\x06 %s", "wlp4s0" },
|
||||
{ wifi_perc, " %s%% ", "wlp4s0" },
|
||||
{ combined_network, "\x06 %s", NULL },
|
||||
/* { wifi_essid, "\x06 %s", "wlp4s0" }, */
|
||||
/* { wifi_perc, " %s%% ", "wlp4s0" }, */
|
||||
{ seperator, "\x07", NULL },
|
||||
{ ipv4_multiple, "\x08 %s ", NULL },
|
||||
{ seperator, "\x09", NULL },
|
||||
|
@ -74,7 +75,7 @@ static const struct arg args[] = {
|
|||
{ netspeed_tx_multiple, " %s ", NULL },
|
||||
{ seperator, "\x0B", NULL },
|
||||
{ battery_perc, "\x0C %s%%", "BAT0" },
|
||||
{ battery_remaining, " %s ", "BAT0" },
|
||||
{ battery_remaining, " %s ", "BAT0" },
|
||||
{ seperator, "\x0D", NULL },
|
||||
{ backlight_perc, "\x0E %s%% ", "intel_backlight" },
|
||||
{ seperator, "\x0F", NULL },
|
||||
|
|
Loading…
Reference in a new issue