From b69e8967d2ba3692820a0dd75897a57a970647f0 Mon Sep 17 00:00:00 2001 From: Unia Date: Sun, 29 Sep 2013 23:06:36 +0200 Subject: [PATCH] remove mpd support, audacious by default, move global variables to main --- Makefile | 13 ++----- README.md | 8 +---- dwmst.c | 100 ++++++++---------------------------------------------- dwmst.h | 11 +----- 4 files changed, 19 insertions(+), 113 deletions(-) diff --git a/Makefile b/Makefile index 83b08c3..d3393cc 100644 --- a/Makefile +++ b/Makefile @@ -3,17 +3,8 @@ CC = gcc PREFIX ?= /usr/local BINPREFIX = ${PREFIX}/bin -# MPD, comment if you don't want it -#MPDLIB = -lmpdclient -#MPDFLAG = -DMPD - -# AUDACIOUS, comment if you don't want it -AUDLIB = `pkg-config --cflags --libs glib-2.0 dbus-glib-1 audclient` -AUDFLAG = -DAUD - -LIBS = -liw -lasound -lX11 ${MPDLIB} ${AUDLIB} -CPPFLAGS = ${MPDFLAG} ${AUDFLAG} -CFLAGS = -Os -pedantic -Wall -Wextra -Wno-format-zero-length ${CPPFLAGS} +LIBS = -liw -lasound -lX11 `pkg-config --cflags --libs glib-2.0 dbus-glib-1 audclient` +CFLAGS = -Os -pedantic -Wall -Wextra -Wno-format-zero-length ${PROG}: ${PROG}.c ${PROG}.h @${CC} ${CFLAGS} ${LIBS} -o ${PROG} ${PROG}.c diff --git a/README.md b/README.md index 33ba7f9..50fab33 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ DWMST This is a hardcoded statusbar for my system and, like Trilby's dwmStatus from which this is forked, it was not meant to be flexible. Flexibility costs memory and processor time. This can, however, be used as a template for your own status bar app. -Note that this was written to work with the statuscolors patch. The colors are int format strings of the sprintf commands. However, as they are mostly nonprintable they can show up oddly, or not at all, depending on your editor. To remove the dependecy on statuscolors simply remove these characters from the format strings. - Installation ------------ @@ -14,10 +12,7 @@ In order to succesfully compile this, you need to have the following dependencie * `libx11` * `wireless_tools` * `alsa-lib` - -The program supports two music players (MPD and Audacious). You can choose which to support by editing the Makefile before compiling. Just comment out the LIB and FLAG lines of the music player you don't want. You will also need certain dependencies to support this output: -* `libmpdclient` for MPD; -* `audacious` for Audacious. +* `audacious` To built and install, simply run @@ -30,7 +25,6 @@ To (re)launch dwmst after suspending your computer, you have to enable the syste ToDo ---- * Code left to clean up: - * MPD; * Alsa; * Improve handling when no battery is present * Be more strict concerning memory use diff --git a/dwmst.c b/dwmst.c index d0b1a55..33c0bee 100644 --- a/dwmst.c +++ b/dwmst.c @@ -6,66 +6,12 @@ #include #include #include -#ifdef MPD -#include -#endif -#ifdef AUD #include #include -#endif #include "dwmst.h" -FILE *infile; -int skfd; -struct wireless_info *winfo; -#ifdef MPD -struct mpd_connection *conn = NULL; -#endif -#ifdef AUD -DBusGProxy *session = NULL; -DBusGConnection *connection = NULL; -#endif - -#ifdef MPD -char *get_mpd(char *buf) { - struct mpd_song *song = NULL; - struct mpd_status *mpd_status = NULL; - const char *title = NULL, *artist = NULL; - - if (mpd_connection_get_error(conn)) - sprintf(buf, NO_MPD_STR); - mpd_command_list_begin(conn, true); - mpd_send_status(conn); - mpd_send_current_song(conn); - mpd_command_list_end(conn); - mpd_status = mpd_recv_status(conn); - if (!mpd_status) - sprintf(buf, NO_MPD_STR); - else { - if (mpd_status_get_state(mpd_status) == MPD_STATE_PLAY) { - mpd_response_next(conn); - song = mpd_recv_song(conn); - title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0); - artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); - sprintf(buf, MPD_STR, title, artist); - mpd_song_free(song); - } else if (mpd_status_get_state(mpd_status) == MPD_STATE_PAUSE) { - mpd_response_next(conn); - song = mpd_recv_song(conn); - title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0); - artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); - sprintf(buf, MPD_P_STR, title, artist); - mpd_song_free(song); - } else if (mpd_status_get_state(mpd_status) == MPD_STATE_STOP) - sprintf(buf, MPD_S_STR); - } - mpd_response_finish(conn); - return buf; -} -#endif -#ifdef AUD -char *get_aud(char *buf) { +char *get_aud(char *buf, DBusGProxy *session) { char *psong = NULL; psong = audacious_remote_get_playlist_title(session, audacious_remote_get_playlist_pos(session)); @@ -81,7 +27,6 @@ char *get_aud(char *buf) { sprintf(buf, AUD_S_STR); return buf; } -#endif char *get_skype(char *buf) { if(access(SKYPE_LOCK, F_OK) == 0) @@ -93,6 +38,7 @@ char *get_skype(char *buf) { int is_up(char *device) { char devpath[35], state[5]; + FILE *infile; sprintf(devpath, "/sys/class/net/%s/operstate", device); infile = fopen(devpath, "r"); @@ -105,17 +51,13 @@ int is_up(char *device) { return 0; } -char *get_net(char *buf) { +char *get_net(char *buf, int skfd, wireless_info *winfo) { if (is_up(WIRED_DEVICE)) sprintf(buf, LAN_STR); else if (is_up(WIRELESS_DEVICE)) { if (iw_get_basic_config(skfd, WIRELESS_DEVICE, &(winfo->b)) > -1) { - if (iw_get_stats(skfd, WIRELESS_DEVICE, &(winfo->stats), &winfo->range, winfo->has_range) >= 0) - winfo->has_stats = 1; - if (iw_get_range_info(skfd, WIRELESS_DEVICE, &(winfo->range)) >= 0) - winfo->has_range = 1; if (winfo->b.has_essid && winfo->b.essid_on) { - sprintf(buf, WLAN_STR, winfo->b.essid, (winfo->stats.qual.qual * 100) / winfo->range.max_qual.qual); + sprintf(buf, WLAN_STR, winfo->b.essid); } } } else @@ -161,6 +103,7 @@ char *get_volume(char *buf) { char *get_battery(char *buf) { DIR *dir; + FILE *infile; char state[8]; long now = -1, full = -1, voltage = -1, rate = -1; int perc, hours, minutes, seconds = -1; @@ -193,9 +136,8 @@ char *get_battery(char *buf) { sprintf(buf, BAT_CHRG_STR, perc, hours, minutes); else { if (perc < BAT_LOW_P || minutes < BAT_LOW_T) - sprintf(buf, BAT_LOW_STR, perc, hours, minutes); - else - sprintf(buf, BAT_STR, perc, hours, minutes); + /*notify*/ + sprintf(buf, BAT_STR, perc, hours, minutes); } } } else @@ -209,6 +151,10 @@ int main(void) { Window root; char status[201], music[100], skype[7], net[30], volume[14], battery[35]; int netloops = 60, musicloops = 10; + int skfd; + struct wireless_info *winfo; + DBusGProxy *session = NULL; + DBusGConnection *connection = NULL; dpy = XOpenDisplay(NULL); if (dpy == NULL) { @@ -218,33 +164,20 @@ int main(void) { root = XRootWindow(dpy, DefaultScreen(dpy)); winfo = malloc(sizeof(struct wireless_info)); memset(winfo, 0, sizeof(struct wireless_info)); + skfd = iw_sockets_open(); -#ifdef MPD - conn = mpd_connection_new(NULL, 0, 30000); -#endif -#ifdef AUD connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE, AUDACIOUS_DBUS_PATH, AUDACIOUS_DBUS_INTERFACE); -#endif - skfd = iw_sockets_open(); while(1) { -#ifdef MPD if (++musicloops > 10) { musicloops = 0; - get_mpd(music); + get_aud(music, session); } -#endif -#ifdef AUD - if (++musicloops > 10) { - musicloops = 0; - get_aud(music); - } -#endif get_skype(skype); if (++netloops > 60) { netloops = 0; - get_net(net); + get_net(net, skfd, winfo); } get_volume(volume); get_battery(battery); @@ -258,10 +191,7 @@ int main(void) { /* NEXT LINES SHOULD NEVER EXECUTE, only here to satisfy Trilby's O.C.D. ;) */ XCloseDisplay(dpy); -#ifdef MPD - mpd_connection_free(conn); -#endif -#ifdef AUD + dbus_g_connection_unref(connection); g_object_unref(session); #endif diff --git a/dwmst.h b/dwmst.h index 559bf3e..019fc07 100644 --- a/dwmst.h +++ b/dwmst.h @@ -12,27 +12,18 @@ #define BATT_VOLT "/sys/class/power_supply/BAT1/voltage_now" #define BATT_CNOW "/sys/class/power_supply/BAT1/power_now" -#ifdef MPD -#define MPD_STR "%s - %s" -#define MPD_P_STR "Paused: %s - %s" -#define MPD_S_STR "" -#define NO_MPD_STR "Geen verbinding" -#endif -#ifdef AUD #define AUD_STR "%s" #define AUD_P_STR "%s" #define AUD_S_STR "" -#endif #define SKYPE_STR "Skype" #define NO_SKYPE_STR "" #define LAN_STR "Verbonden" -#define WLAN_STR "%s %d%%" +#define WLAN_STR "%s" #define NO_CON_STR "Geen verbinding" #define VOL_STR "Volume %d%%" #define VOL_MUTE_STR "Volume M" #define BAT_FULL_STR "Batterij F" #define BAT_STR "Batterij D%d%%, %02d:%02d" -#define BAT_LOW_STR "Batterij D%d%%, %02d:%02d" #define BAT_CHRG_STR "Batterij C%d%%, %02d:%02d" #define BAT_UNK_STR "Batterij U" #define NO_BAT_STR "Geen batterij"