Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Commit

Permalink
added support for wired connection, might reimplement this better
Browse files Browse the repository at this point in the history
  • Loading branch information
Unia committed Apr 14, 2013
1 parent 8a6fa2c commit eb2ac26
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
40 changes: 23 additions & 17 deletions dwmst.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 8 additions & 5 deletions dwmst.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include <audacious/audctrl.h>
#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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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;
Expand Down

0 comments on commit eb2ac26

Please sign in to comment.