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

Commit

Permalink
header file added and cleanup in it
Browse files Browse the repository at this point in the history
  • Loading branch information
Unia committed Mar 11, 2013
1 parent 78b8daf commit ee09f8a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LIBS = -liw -lasound -lX11 ${MPDLIB} ${AUDLIB}
CPPFLAGS = ${MPDFLAG} ${AUDFLAG} ${CLKFLAG}
CFLAGS = -Os -Wall -Wextra -pedantic -Wno-format-zero-length -Wno-unused-parameter -Wno-unused-result ${CPPFLAGS}

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

Expand Down
2 changes: 1 addition & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pkgname=dwm-status
pkgver=20130308
pkgver=20130310
pkgrel=1
pkgdesc='A hardcoded statusbar for DWM'
arch=(any)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ In order to succesfully compile this, you need to have the following dependencie
* alsa-lib

ToDo:
* Make a header file for cleanliness and practice;
* Fix statuscolor colorcodes messing up the statustext.
89 changes: 2 additions & 87 deletions dwmst.c
Original file line number Diff line number Diff line change
@@ -1,103 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <locale.h>
#include <X11/Xlib.h>
#include <iwlib.h>
#include <alsa/asoundlib.h>
#ifdef CLK
#include <time.h>
#endif
#ifdef MPD
#include <mpd/client.h>
#endif
#ifdef AUD
#include <audacious/dbus.h>
#include <audacious/audctrl.h>
#endif

#define WIFI "wlan0" /* 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 */
#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"
#define BATT_VOLT "/sys/class/power_supply/BAT0/voltage_now"
#define BATT_CNOW "/sys/class/power_supply/BAT0/current_now"
/* 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 */
#define MPD_P_STR "Paused: \x02 %s \x01 - \x02 %s " /* MPD, paused */
#define MPD_S_STR "" /* MPD, stopped */
#define NO_MPD_STR "Geen verbinding " /* MPD, can't connect */
#endif
#ifdef AUD
#define MUSIC_STR "\x02%s " /* Music, playing */
#define MUSIC_P_STR "P: \x02 %s " /* Music, paused */
#define MUSIC_S_STR "" /* Music, stopped */
#endif
#define SKYPE_STR "\x02Skype " /*Skype is running */
#define NO_SKYPE_STR "" /* Skype is not running */
#define WIFI_STR "\x01 %s \x02 %d%% " /* WIFI */
#define NO_WIFI_STR "\x01 Geen verbinding " /* WIFI, no connection */
#define VOL_STR "\x01 Volume \x02 %d%% " /* Volume */
#define VOL_MUTE_STR "\x01 Volume \x02 × " /* Volume, muted */
#define BAT_FULL_STR "\x01 Batterij \x02 F %d%%" /* Battery, full */
#define BAT_STR "\x01 Batterij \x02 D %d%%, %02d:%02d resterend" /* Battery, discharging, above BATT_LOW percentage */
#define BAT_LOW_STR "\x01 Batterij \x02 D %d%%, %02d:%02d resterend" /* Battery, discharging, below BATT_LOW percentage */
#define BAT_CHRG_STR "\x01 Batterij \x02 C %d%%, %02d:%02d tot opgeladen" /* Battery, AC */
#ifdef CLK
#define DATE_TIME_STR "\x01 %a \x02%d \x01%b,\x02 %H:%M" /* This is a strftime format string which is passed localtime */
#endif
#include "dwmst.h"

int main() {
Display *dpy;
Window root;
FILE *infile;
int perc, skfd, mute = 0, realvol = 0, wifiloops = 60, musicloops = 10;
int hours, minutes, seconds = -1;
long now = -1, full = -1, voltage = -1, rate = -1, vol = 0, max = 0, min = 0;
char statnext[100], status[200], wifistring[30], musicstring[100];
struct wireless_info *winfo;
snd_mixer_t *handle;
snd_mixer_selem_id_t *vol_info, *mute_info;
snd_mixer_elem_t *pcm_mixer;
snd_mixer_elem_t *mas_mixer;
#ifdef CLK
time_t current;
#endif
#ifdef MPD
struct mpd_song *song = NULL;
const char *title = NULL;
const char *artist = NULL;
#endif
#ifdef AUD
int playpos;
char *psong;
DBusGProxy *session;
DBusGConnection *connection;
#endif
/* 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));
root = XRootWindow(dpy, DefaultScreen(dpy));
winfo = (struct wireless_info *) calloc(1, sizeof(struct wireless_info));
#ifdef CLK
setlocale(LC_ALL, "");
#endif
#ifdef AUD
g_type_init();
session = NULL;
connection = NULL;
psong = NULL;
#endif
/* MAIN LOOP STARTS HERE */
for (;;) {
Expand Down
81 changes: 81 additions & 0 deletions dwmst.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <locale.h>
#include <X11/Xlib.h>
#include <iwlib.h>
#include <alsa/asoundlib.h>
#ifdef CLK
#include <time.h>
#endif
#ifdef MPD
#include <mpd/client.h>
#endif
#ifdef AUD
#include <audacious/dbus.h>
#include <audacious/audctrl.h>
#endif

#define WIFI "wlan0" /* 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 */
#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"
#define BATT_VOLT "/sys/class/power_supply/BAT0/voltage_now"
#define BATT_CNOW "/sys/class/power_supply/BAT0/current_now"
/* 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 */
#define MPD_P_STR "Paused: \x02 %s \x01 - \x02 %s " /* MPD, paused */
#define MPD_S_STR "" /* MPD, stopped */
#define NO_MPD_STR "Geen verbinding " /* MPD, can't connect */
#endif
#ifdef AUD
#define MUSIC_STR "\x02%s " /* Music, playing */
#define MUSIC_P_STR "P: \x02%s " /* Music, paused */
#define MUSIC_S_STR "" /* Music, stopped */
#endif
#define SKYPE_STR "\x02Skype " /*Skype is running */
#define NO_SKYPE_STR "" /* Skype is not running */
#define WIFI_STR "\x01 %s \x02 %d%% " /* WIFI */
#define NO_WIFI_STR "\x01 Geen verbinding " /* WIFI, no connection */
#define VOL_STR "\x01 Volume \x02 %d%% " /* Volume */
#define VOL_MUTE_STR "\x01 Volume \x02 × " /* Volume, muted */
#define BAT_FULL_STR "\x01 Batterij \x02 F %d%%" /* Battery, full */
#define BAT_STR "\x01 Batterij \x02 D %d%%, %02d:%02d resterend" /* Battery, discharging, above BATT_LOW percentage */
#define BAT_LOW_STR "\x01 Batterij \x02 D %d%%, %02d:%02d resterend" /* Battery, discharging, below BATT_LOW percentage */
#define BAT_CHRG_STR "\x01 Batterij \x02 C %d%%, %02d:%02d tot opgeladen" /* Battery, AC */
#ifdef CLK
#define DATE_TIME_STR "\x01 %a \x02%d \x01%b,\x02 %H:%M" /* This is a strftime format string which is passed localtime */
#endif

Display *dpy;
Window root;
FILE *infile;
int perc, hours, minutes, seconds = -1, skfd, mute = 0, realvol = 0, wifiloops = 60, musicloops = 10;
long now = -1, full = -1, voltage = -1, rate = -1, vol = 0, max = 0, min = 0;
char statnext[100], status[200], wifistring[30], musicstring[100];
struct wireless_info *winfo;
snd_mixer_t *handle;
snd_mixer_elem_t *pcm_mixer, *mas_mixer;
snd_mixer_selem_id_t *vol_info, *mute_info;
#ifdef CLK
time_t current;
#endif
#ifdef MPD
struct mpd_song *song = NULL;
const char *title = NULL;
const char *artist = NULL;
#endif
#ifdef AUD
int playpos;
char *psong = NULL;
DBusGProxy *session = NULL;
DBusGConnection *connection = NULL;
#endif

0 comments on commit ee09f8a

Please sign in to comment.