From eb2ac265f458cfa7733c116d12e02532bb19eb24 Mon Sep 17 00:00:00 2001 From: Unia Date: Sun, 14 Apr 2013 18:16:28 +0200 Subject: [PATCH] added support for wired connection, might reimplement this better --- dwmst.c | 40 +++++++++++++++++++++++----------------- dwmst.h | 13 ++++++++----- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/dwmst.c b/dwmst.c index c3f82d3..e3d9527 100644 --- a/dwmst.c +++ b/dwmst.c @@ -84,26 +84,32 @@ int main() { } else sprintf(statnext, NO_SKYPE_STR); strcat(status, statnext); - /* WIFI */ - if (++wifiloops > 60) { - wifiloops = 0; - skfd = iw_sockets_open(); - if (iw_get_basic_config(skfd, WIFI, &(winfo->b)) > -1) { - if (iw_get_stats(skfd, WIFI, &(winfo->stats), &winfo->range, winfo->has_range) >= 0) - winfo->has_stats = 1; - if (iw_get_range_info(skfd, WIFI, &(winfo->range)) >= 0) - winfo->has_range = 1; - if (winfo->b.has_essid) { - if (winfo->b.essid_on) - sprintf(wifistring, WIFI_STR, winfo->b.essid, (winfo->stats.qual.qual * 100) / winfo->range.max_qual.qual); - else - sprintf(wifistring, NO_WIFI_STR); + /* NET */ + if (++netloops > 60) { + netloops = 0; + infile = fopen(NET_FILE, "r"); + fscanf(infile, "%d\n", &net); fclose(infile); + if(net == 1) + sprintf(netstring, LAN_STR); + else { + skfd = iw_sockets_open(); + if (iw_get_basic_config(skfd, WLAN, &(winfo->b)) > -1) { + if (iw_get_stats(skfd, WLAN, &(winfo->stats), &winfo->range, winfo->has_range) >= 0) + winfo->has_stats = 1; + if (iw_get_range_info(skfd, WLAN, &(winfo->range)) >= 0) + winfo->has_range = 1; + if (winfo->b.has_essid) { + if (winfo->b.essid_on) + sprintf(netstring, WLAN_STR, winfo->b.essid, (winfo->stats.qual.qual * 100) / winfo->range.max_qual.qual); + else + sprintf(netstring, NO_WLAN_STR); + } } + iw_sockets_close(skfd); + memset(winfo, 0, sizeof(struct wireless_info)); } - iw_sockets_close(skfd); - memset(winfo, 0, sizeof(struct wireless_info)); } - strcat(status,wifistring); + strcat(status, netstring); /* Audio volume */ snd_mixer_open(&handle, 0); snd_mixer_attach(handle, "default"); diff --git a/dwmst.h b/dwmst.h index 853d981..1b1b5f8 100644 --- a/dwmst.h +++ b/dwmst.h @@ -17,7 +17,8 @@ #include #endif -#define WIFI "wlp5s0" /* Wireless interface */ +#define LAN "enp3s0" /* Wired interface */ +#define WLAN "wlp5s0" /* Wireless interface */ #define BATT_LOW_P 11 /* Below BATT_LOW percentage left on battery, the battery display turns red */ #define BATT_LOW_T 3 /* Same as above, but now minutes instead of percentage */ #define INTERVAL 1 /* Sleeps for INTERVAL seconds between updates */ @@ -29,6 +30,7 @@ #define BATT_STAT "/sys/class/power_supply/BAT0/status" #define BATT_VOLT "/sys/class/power_supply/BAT0/voltage_now" #define BATT_CNOW "/sys/class/power_supply/BAT0/current_now" +#define NET_FILE "/sys/class/net/enp3s0/carrier" /* Display format strings. Defaults make extensive use of escape characters for colors which require colorstatus patch. */ #ifdef MPD #define MPD_STR "\x02%s \x01 - \x02 %s " /* MPD, playing */ @@ -43,8 +45,9 @@ #endif #define SKYPE_STR "\x02Skype \x01" /*Skype is running */ #define NO_SKYPE_STR "" /* Skype is not running */ -#define WIFI_STR "%s \x02%d%% \x01" /* WIFI */ -#define NO_WIFI_STR "Geen verbinding \x01" /* WIFI, no connection */ +#define LAN_STR "Verbonden \x01" /* LAN */ +#define WLAN_STR "%s \x02%d%% \x01" /* WLAN */ +#define NO_WLAN_STR "Geen verbinding \x01" /* WLAN, no connection */ #define VOL_STR "Volume \x02%d%% \x01" /* Volume */ #define VOL_MUTE_STR "Volume \x02M \x01" /* Volume, muted */ #define BAT_FULL_STR "Batterij\x02 F %d%% " /* Battery, full */ @@ -59,9 +62,9 @@ Display *dpy; Window root; FILE *infile; -int perc, hours, minutes, seconds = -1, skfd, mute = 0, realvol = 0, wifiloops = 60, musicloops = 10; +int perc, hours, minutes, seconds = -1, net, skfd, mute = 0, realvol = 0, netloops = 60, musicloops = 10; long now = -1, full = -1, voltage = -1, rate = -1, vol = 0, max = 0, min = 0; -char state[8], statnext[100], status[200], wifistring[30], musicstring[100]; +char state[8], statnext[100], status[200], netstring[30], musicstring[100]; struct wireless_info *winfo; snd_mixer_t *handle; snd_mixer_elem_t *pcm_mixer, *mas_mixer;