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

Commit

Permalink
remove mpd support, audacious by default, move global variables to main
Browse files Browse the repository at this point in the history
  • Loading branch information
Unia committed Sep 29, 2013
1 parent b540256 commit b69e896
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 113 deletions.
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ 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
------------

In order to succesfully compile this, you need to have the following dependencies installed:
* `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

Expand All @@ -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
Expand Down
100 changes: 15 additions & 85 deletions dwmst.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,12 @@
#include <dirent.h>
#include <iwlib.h>
#include <alsa/asoundlib.h>
#ifdef MPD
#include <mpd/client.h>
#endif
#ifdef AUD
#include <audacious/dbus.h>
#include <audacious/audctrl.h>
#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));
Expand All @@ -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)
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions dwmst.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit b69e896

Please sign in to comment.