2006-03-06
* Fixed battery problems when charged
+ * MPD code handles broken pipe now, instead of just killing conky
2006-03-05
* Added patch to make $cpu stuff work on alpha (thanks Thomas Cort)
<varlistentry>
<term>
+ <command><option>mpd_smart<option></command>
+ </term>
+ <listitem>
+ Prints the song name in either the form "artist - title" or file name, depending on whats available
+ <para></para></listitem>
+</varlistentry>
+
+<varlistentry>
+ <term>
<command><option>new_mails</option></command>
</term>
<listitem>
OBJ_mpd_name,
OBJ_mpd_file,
OBJ_mpd_percent,
+ OBJ_mpd_smart,
#endif
#if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
OBJ_xmms_status,
info.mpd.status = 0;
}
break;
+ case OBJ_mpd_smart:
+ if (info.mpd.artist) {
+ free(info.mpd.artist);
+ info.mpd.artist = 0;
+ }
+ if (info.mpd.title) {
+ free(info.mpd.title);
+ info.mpd.title = 0;
+ }
+ if (info.mpd.file) {
+ free(info.mpd.file);
+ info.mpd.file = 0;
+ }
+ break;
case OBJ_mpd_host:
#endif
#ifdef BMPX
END OBJ(mpd_name, INFO_MPD)
END OBJ(mpd_file, INFO_MPD)
END OBJ(mpd_percent, INFO_MPD)
- END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
- INFO_MPD) END OBJ(mpd_bitrate,
- INFO_MPD)
- END OBJ(mpd_status, INFO_MPD)
- END OBJ(mpd_bar, INFO_MPD)
- (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
- END
+ END OBJ(mpd_album, INFO_MPD)
+ END OBJ(mpd_vol, INFO_MPD)
+ END OBJ(mpd_bitrate, INFO_MPD)
+ END OBJ(mpd_status, INFO_MPD)
+ END OBJ(mpd_bar, INFO_MPD)
+ (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ END OBJ(mpd_smart, INFO_MPD) END
#endif
#if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
OBJ(xmms_status, INFO_XMMS) END
(int) (cur->mpd.progress *
255.0f));
}
+ OBJ(mpd_smart) {
+ if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
+ snprintf(p, p_max_size, "%s", cur->mpd.file);
+ } else {
+ snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
+ }
+ }
#endif
#if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
OBJ(xmms_status) {
#include <X11/extensions/Xdbe.h>
#endif
-#define ATOM(a) XInternAtom(display, #a, False)
+#define ATOM(a) XInternAtom(display, #a, True)
#ifdef OWN_WINDOW
enum _window_hints {
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
+#include <sys/signal.h>
#ifndef MPD_NO_IPV6
#ifdef AF_INET6
#endif
#endif
+static char sigpipe = 0;
+
#define COMMAND_LIST 1
#define COMMAND_LIST_OK 2
mpd_Connection *connection = malloc(sizeof(mpd_Connection));
struct timeval tv;
fd_set fds;
+ struct sigaction sapipe; /* definition of signal action */
+
#ifdef MPD_HAVE_IPV6
struct sockaddr_in6 sin6;
#endif
connection->listOks = 0;
connection->doneListOk = 0;
connection->returnElement = NULL;
+ sigpipe = 0;
if (!(he = gethostbyname(host))) {
snprintf(connection->errorStr, MPD_BUFFER_MAX_LENGTH,
}
mpd_setConnectionTimeout(connection, timeout);
+
+ /* install the signal handler */
+ sapipe.sa_handler = mpd_signalHandler;
+// sapipe.sa_mask = 0;
+ sapipe.sa_flags = 0;
+ sapipe.sa_restorer = NULL;
+ sigaction(SIGPIPE,&sapipe,NULL);
/* connect stuff */
{
tv.tv_sec = connection->timeout.tv_sec;
tv.tv_usec = connection->timeout.tv_usec;
- while ((ret =
- select(connection->sock + 1, NULL, &fds, NULL, &tv) == 1)
- || (ret == -1 && errno == EINTR)) {
- ret =
- send(connection->sock, commandPtr, commandLen,
- MSG_DONTWAIT);
- if (ret <= 0) {
- if (ret == EAGAIN || ret == EINTR)
- continue;
- snprintf(connection->errorStr,
- MPD_BUFFER_MAX_LENGTH,
- "problems giving command \"%s\"",
- command);
+ if (sigpipe) {
+ perror("");
+ snprintf(connection->errorStr, MPD_BUFFER_MAX_LENGTH, "got SIGINT");
+ connection->error = MPD_ERROR_SENDING;
+ return;
+ }
+ while ((ret = select(connection->sock + 1, NULL, &fds, NULL, &tv) == 1) || (ret == -1 && errno == EINTR)) {
+ if (sigpipe) {
+ perror("");
+ snprintf(connection->errorStr, MPD_BUFFER_MAX_LENGTH, "got SIGINT");
connection->error = MPD_ERROR_SENDING;
return;
} else {
- commandPtr += ret;
- commandLen -= ret;
+ ret = send(connection->sock, commandPtr, commandLen, MSG_DONTWAIT);
+ if (ret <= 0) {
+ if (ret == EAGAIN || ret == EINTR)
+ continue;
+ snprintf(connection->errorStr, MPD_BUFFER_MAX_LENGTH, "problems giving command \"%s\"", command);
+ connection->error = MPD_ERROR_SENDING;
+ return;
+ } else {
+ commandPtr += ret;
+ commandLen -= ret;
+ }
+ if (commandLen <= 0)
+ break;
}
-
- if (commandLen <= 0)
- break;
}
if (commandLen > 0) {
connection->commandList = 0;
mpd_executeCommand(connection, "command_list_end\n");
}
+
+void mpd_signalHandler(int signal)
+{
+ if (signal == SIGPIPE) {
+ fprintf(stderr, "Conky: recieved SIGPIPE from MPD connection\n");
+ sigpipe = 1;
+ }
+}
+
* returns -1 if it advanced to an OK or ACK */
int mpd_nextListOkCommand(mpd_Connection * connection);
+/* handles SIGPIPE from full close on the server side */
+ void mpd_signalHandler(int);
+
#ifdef __cplusplus
}
#endif
/* charged */
/* thanks to Lukas Zapletal <lzap@seznam.cz> */
else if (strcmp(charging_state, "charged") == 0) {
- if (acpi_last_full != 0
- && remaining_capacity != acpi_last_full)
- sprintf(last_battery_str, "charged %d%%",
- remaining_capacity * 100 /
- design_capacity);
- else
+ if (acpi_last_full != 0 && remaining_capacity != acpi_last_full) {
+ sprintf(last_battery_str, "charged %d%%", remaining_capacity * 100 / design_capacity);
+ } else {
strcpy(last_battery_str, "charged");
+ }
}
/* unknown, probably full / AC */
else {
if (TEST_HINT(window.hints,HINT_STICKY)) {
fprintf(stderr, "Conky: hint - sticky\n"); fflush(stderr);
- xa = ATOM(_NET_WM_STATE);
+ xa = ATOM(_NET_WM_DESKTOP);
if (xa != None) {
- Atom xa_prop = ATOM(_NET_WM_STATE_STICKY);
+ uint32_t xa_prop = UINT32_MAX;
XChangeProperty(display, window.window, xa,
- XA_ATOM, 32,
+ XA_CARDINAL, 32,
PropModeAppend,
(unsigned char *) &xa_prop,
1);