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

Commit

Permalink
several updates; //->/* + makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Unia committed Jan 22, 2013
1 parent 6bee5b6 commit 4fb49db
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PROG = dwmst
PREFIX ?= /usr/local

# MPD, comment if you don't want it
#MPDLIB = -lmpdclient
Expand All @@ -12,15 +13,17 @@ LIBS = -liw -lasound -lX11 ${MPDLIB} ${AUDLIB}
CPPFLAGS = ${MPDFLAG} ${AUDFLAG}
CFLAGS = -Os -Wall -Wno-unused-parameter -Wno-unused-result ${CPPFLAGS}

$(PROG): $(PROG).c
@$(CC) $(CFLAGS) $(LIBS) -o $(PROG) $(PROG).c
@strip $(PROG)
${PROG}: ${PROG}.c
@${CC} ${CFLAGS} ${LIBS} -o ${PROG} ${PROG}.c
@strip ${PROG}

clean:
rm -f $(PROG)
rm -f ${PROG}

install:
mkdir -p $(DESTDIR)/usr/bin
mkdir -p $(DESTDIR)/usr/lib/systemd/system
install -Dm755 $(PROG) $(DESTDIR)/usr/bin/
install -Dm644 $(PROG).service $(DESTDIR)/usr/lib/systemd/system/
install -Dm755 ${PROG} ${DESTDIR}${PREFIX}/bin/${PROG}
install -Dm644 ${PROG}.service ${DESTDIR}/usr/lib/systemd/system/${PROG}.service

uninstall:
rm -f ${PREFIX}/bin/${PROG}
rm -f /usr/lib/systemd/system/${PROG}.service
82 changes: 41 additions & 41 deletions dwmst.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@
#include <audacious/audctrl.h>
#endif

#define WIFI "wlan0" // Wireless interface
#define BATT_LOW 11 // Below BATT_LOW percentage left on battery, the battery display turns red
#define INTERVAL 1 // Sleeps for INTERVAL seconds between updates
#define VOL_CH "Master" // Channel to watch for volume
// Files read for system info:
#define WIFI "wlan0" /* Wireless interface */
#define BATT_LOW 11 /* Below BATT_LOW percentage left on battery, the battery display turns red */
#define INTERVAL 1 /* Sleeps for INTERVAL seconds between updates */
#define VOL_CH "Master" /* Channel to watch for volume */
/* Files read for system info: */
#define SKYPE_FILE "/home/jente/.Skype/jente_etnej/main.lock"
#define BATT_NOW "/sys/class/power_supply/BAT0/charge_now"
#define BATT_FULL "/sys/class/power_supply/BAT0/charge_full"
#define BATT_STAT "/sys/class/power_supply/BAT0/status"
// Display format strings. Defaults make extensive use of escape characters for colors which require colorstatus patch.
/* Display format strings. Defaults make extensive use of escape characters for colors which require colorstatus patch. */
#ifdef MPD
#define MPD_STR "%s \x02-\x01 %s \x02•\x01 " // MPD, playing
#define MPD_P_STR "Paused\x02:\x01 %s \x02-\x01 %s \x02•\x01 " // MPD, paused
#define MPD_S_STR "" // MPD, stopped
#define NO_MPD_STR "Geen verbinding \x02•\x01 " // MPD, can't connect
#define MPD_STR "%s \x02-\x01 %s \x02•\x01 " /* MPD, playing */
#define MPD_P_STR "Paused\x02:\x01 %s \x02-\x01 %s \x02•\x01 " /* MPD, paused */
#define MPD_S_STR "" /* MPD, stopped */
#define NO_MPD_STR "Geen verbinding \x02•\x01 " /* MPD, can't connect */
#endif
#ifdef AUD
#define MUSIC_STR "%s \x02•\x01 " // Music, playing
#define MUSIC_P_STR "Paused\x02:\x01 %s \x02•\x01 " // Music, paused
#define MUSIC_S_STR "" // Music, stopped
#define MUSIC_STR "%s \x02•\x01 " /* Music, playing */
#define MUSIC_P_STR "Paused\x02:\x01 %s \x02•\x01 " /* Music, paused */
#define MUSIC_S_STR "" /* Music, stopped */
#endif
#define SKYPE_STR "Skype \x02•\x01 " // Skype is running
#define NO_SKYPE_STR "" // Skype is not running
#define WIFI_STR " %s %d%% " // WIFI
#define NO_WIFI_STR " Geen verbinding " // WIFI, no connection
#define VOL_STR "\x02•\x01 %d%% " // Volume
#define VOL_MUTE_STR "\x02•\x01 × " // Volume, muted
#define BAT_STR "\x02•\x01 D %d%% " // Battery, BAT, above BATT_LOW percentage
#define BAT_LOW_STR "\x02•\x03 D %d%% " // Battery, BAT, below BATT_LOW percentage
#define BAT_FULL_STR "\x02•\x04 F \x01%d%% " // Battery, full
#define BAT_CHRG_STR "\x02•\x01 C %d%% " // Battery, AC
#define DATE_TIME_STR "\x02•\x01 %a %d %b\x02,\x01 %H:%M " // This is a strftime format string which is passed localtime
#define SKYPE_STR "Skype \x02•\x01 " /* Skype is running */
#define NO_SKYPE_STR "" /* Skype is not running */
#define WIFI_STR " %s %d%% " /* WIFI */
#define NO_WIFI_STR " Geen verbinding " /* WIFI, no connection */
#define VOL_STR "\x02•\x01 %d%% " /* Volume */
#define VOL_MUTE_STR "\x02•\x01 × " /* Volume, muted */
#define BAT_STR "\x02•\x01 D %d%% " /* Battery, BAT, above BATT_LOW percentage */
#define BAT_LOW_STR "\x02•\x03 D %d%% " /* Battery, BAT, below BATT_LOW percentage */
#define BAT_FULL_STR "\x02•\x04 F \x01%d%% " /* Battery, full */
#define BAT_CHRG_STR "\x02•\x01 C %d%% " /* Battery, AC */
#define DATE_TIME_STR "\x02•\x01 %a %d %b\x02,\x01 %H:%M " /* This is a strftime format string which is passed localtime */

int main() {
Display *dpy;
Expand All @@ -73,17 +73,17 @@ int main() {
psong = NULL;
g_type_init();
#endif
// Setup X display and root window id:
/* Setup X display and root window id: */
dpy=XOpenDisplay(NULL);
if (dpy == NULL) {
fprintf(stderr, "ERROR: could not open display\n");
exit(1);
}
root = XRootWindow(dpy,DefaultScreen(dpy));
// MAIN LOOP STARTS HERE
/* MAIN LOOP STARTS HERE */
for (;;) {
status[0]='\0';
// MUSIC
/* MUSIC */
#ifdef MPD
if (++musicloops > 10) {
musicloops=0;
Expand Down Expand Up @@ -151,7 +151,7 @@ int main() {
}
strcat(status,musicstring);
#endif
// SKYPE
/* SKYPE */
infile = fopen(SKYPE_FILE,"r");
if (infile) {
sprintf(statnext,SKYPE_STR);
Expand All @@ -160,16 +160,16 @@ int main() {
else
sprintf(statnext,NO_SKYPE_STR);
strcat(status,statnext);
// WIFI
/* 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), // set present winfo variables
if (iw_get_stats(skfd, WIFI, &(winfo->stats), /* set present winfo variables */
&winfo->range, winfo->has_range) >= 0) {
winfo->has_stats = 1;
}
if (iw_get_range_info(skfd, WIFI, &(winfo->range)) >= 0) { // set present winfo variables
if (iw_get_range_info(skfd, WIFI, &(winfo->range)) >= 0) { /* set present winfo variables */
winfo->has_range = 1;
}
if (winfo->b.has_essid) {
Expand All @@ -185,23 +185,23 @@ int main() {
memset(winfo, 0, sizeof(struct wireless_info));
}
strcat(status,wifistring);
// Audio volume
snd_mixer_t *handle; // init alsa
/* Audio volume */
snd_mixer_t *handle; /* init alsa */
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, "default");
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_t *vol_info; // init channel with volume info
snd_mixer_selem_id_t *vol_info; /* init channel with volume info */
snd_mixer_selem_id_malloc(&vol_info);
snd_mixer_selem_id_set_name(vol_info, VOL_CH);
snd_mixer_elem_t* pcm_mixer = snd_mixer_find_selem(handle, vol_info);
snd_mixer_selem_get_playback_volume_range(pcm_mixer, &min, &max); // get volume
snd_mixer_selem_get_playback_volume_range(pcm_mixer, &min, &max); /* get volume */
snd_mixer_selem_get_playback_volume(pcm_mixer, SND_MIXER_SCHN_MONO, &vol);
snd_mixer_selem_id_t *mute_info; // init channel with mute info
snd_mixer_selem_id_t *mute_info; /* init channel with mute info */
snd_mixer_selem_id_malloc(&mute_info);
snd_mixer_selem_id_set_name(mute_info, VOL_CH);
snd_mixer_elem_t* mas_mixer = snd_mixer_find_selem(handle, mute_info);
snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO, &mute); // get mute state
snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO, &mute); /* get mute state */

if(mute == 0)
sprintf(statnext, VOL_MUTE_STR);
Expand All @@ -216,7 +216,7 @@ int main() {
if (handle)
snd_mixer_close(handle);
strcat(status,statnext);
// Power / Battery
/* Power / Battery */
infile = fopen(BATT_NOW,"r");
fscanf(infile,"%ld\n",&lnum1); fclose(infile);
infile = fopen(BATT_FULL,"r");
Expand All @@ -237,16 +237,16 @@ int main() {
sprintf(statnext,BAT_STR,num);
}
strcat(status,statnext);
// Time
/* Time */
time(&current);
strftime(statnext,38,DATE_TIME_STR,localtime(&current));
strcat(status,statnext);
// Set root name
/* Set root name */
XStoreName(dpy,root,status);
XFlush(dpy);
sleep(INTERVAL);
}
// NEXT LINES SHOULD NEVER EXECUTE, only here to satisfy Trilby's O.C.D. ;)
/* NEXT LINES SHOULD NEVER EXECUTE, only here to satisfy Trilby's O.C.D. ;) */
XCloseDisplay(dpy);
return 0;
}

0 comments on commit 4fb49db

Please sign in to comment.