1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

sticky hints

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@548 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2006-03-07 04:23:55 +00:00
parent 8ad961d96f
commit ac23be3d25
8 changed files with 95 additions and 35 deletions

View File

@ -2,6 +2,7 @@
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)

View File

@ -836,6 +836,15 @@
<para></para></listitem>
</varlistentry>
<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>

View File

@ -890,6 +890,7 @@ enum text_object_type {
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,
@ -1182,6 +1183,20 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
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
@ -1891,13 +1906,13 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
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
@ -3186,6 +3201,13 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
(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) {

View File

@ -297,7 +297,7 @@ char tmpstring2[TEXT_BUFFER_SIZE];
#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 {

View File

@ -45,6 +45,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/signal.h>
#ifndef MPD_NO_IPV6
#ifdef AF_INET6
@ -52,6 +53,8 @@
#endif
#endif
static char sigpipe = 0;
#define COMMAND_LIST 1
#define COMMAND_LIST_OK 2
@ -136,6 +139,8 @@ mpd_Connection *mpd_newConnection(const char *host, int port,
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
@ -149,6 +154,7 @@ mpd_Connection *mpd_newConnection(const char *host, int port,
connection->listOks = 0;
connection->doneListOk = 0;
connection->returnElement = NULL;
sigpipe = 0;
if (!(he = gethostbyname(host))) {
snprintf(connection->errorStr, MPD_BUFFER_MAX_LENGTH,
@ -204,6 +210,13 @@ mpd_Connection *mpd_newConnection(const char *host, int port,
}
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 */
{
@ -367,28 +380,33 @@ void mpd_executeCommand(mpd_Connection * connection, char *command)
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) {
@ -1515,3 +1533,12 @@ void mpd_sendCommandListEnd(mpd_Connection * connection)
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;
}
}

View File

@ -503,6 +503,9 @@ extern "C" {
* 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

View File

@ -1186,13 +1186,11 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
/* 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 {

View File

@ -312,11 +312,11 @@ void init_window(int own_window, int w, int h, int set_trans, int back_colour, c
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);