1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-28 21:19:10 +00:00

fixed graph width issue

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@262 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2005-09-04 03:43:18 +00:00
parent d1c038f7ba
commit 471fcabc90
5 changed files with 112 additions and 88 deletions

View File

@ -101,6 +101,9 @@ Lucas Brutschy <lbrutschy at users dot sourceforge dot net>
Moncelier Camille <pixdamix at users dot sourceforge dot net>
METAR patch
nathanj439 <nathanj439 at users dot sourceforge dot net>
MPD time fix
roiban adi <adiroiban at users dot sourceforge dot net>
hex colour patch

View File

@ -1,5 +1,9 @@
# $Id$
2005-09-03
* MPD patch (sf.net patch 1281108)
* Fixed graph width bug
2005-08-31
* FreeBSD support was added

View File

@ -385,7 +385,7 @@ static int special_count;
static int special_index; /* used when drawing */
#endif /* X11 */
#define MAX_GRAPH_DEPTH 512 /* why 512? who knows. */
#define MAX_GRAPH_DEPTH 256 /* why 256? cause an array of more then 256 doubles seems excessive, and who needs that kind of precision anyway? */
static struct special_t *new_special(char *buf, int t)
{
@ -394,18 +394,6 @@ static struct special_t *new_special(char *buf, int t)
buf[0] = SPECIAL_CHAR;
buf[1] = '\0';
if (t == GRAPH && specials[special_count].graph == NULL) {
if (specials[special_count].width > 0
&& specials[special_count].width < MAX_GRAPH_DEPTH)
specials[special_count].graph_width = specials[special_count].width - 3; // subtract 3 for the box
else
specials[special_count].graph_width =
MAX_GRAPH_DEPTH;
specials[special_count].graph =
calloc(specials[special_count].graph_width,
sizeof(double));
specials[special_count].graph_scale = 100;
}
specials[special_count].type = t;
return &specials[special_count++];
}
@ -552,7 +540,16 @@ static unsigned int adjust_colors(unsigned int color)
static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
{
struct special_t *s = new_special(buf, GRAPH);
s->width = (w < MAX_GRAPH_DEPTH) ? w : MAX_GRAPH_DEPTH;
s->width = w;
if (s->graph == NULL) {
if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
s->graph_width = s->width - 3; // subtract 3 for the box
} else {
s->graph_width = MAX_GRAPH_DEPTH - 3;
}
s->graph = malloc(s->graph_width * sizeof(double));
s->graph_scale = 100;
}
s->height = h;
s->first_colour = adjust_colors(first_colour);
s->last_colour = adjust_colors(second_colour);
@ -561,9 +558,9 @@ static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsign
} else {
s->scaled = 1;
}
if (s->width) {
/*if (s->width) {
s->graph_width = s->width - 3; // subtract 3 for rectangle around
}
}*/
if (s->scaled) {
s->graph_scale = 1;
} else {
@ -1126,7 +1123,7 @@ if (s[0] == '#') {
arg += 4;
}
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
} else {
} else {
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
obj->data.cpu_index = 0;
}
@ -2784,11 +2781,11 @@ static void generate_text()
}
seconds = tmp;
if (days > 0)
snprintf(p, n, "%i days %i:%i:%2i",
snprintf(p, n, "%i days %i:%02i:%02i",
days, hours, minutes,
seconds);
else if (days > 0)
snprintf(p, n, "%i:%i:%02i", hours,
else if (hours > 0)
snprintf(p, n, "%i:%02i:%02i", hours,
minutes, seconds);
else
snprintf(p, n, "%i:%02i", minutes,
@ -2813,11 +2810,11 @@ static void generate_text()
seconds = tmp;
if (days > 0)
snprintf(p, n,
"%i days %i:%i:%02i",
"%i days %i:%02i:%02i",
days, hours, minutes,
seconds);
else if (days > 0)
snprintf(p, n, "%i:%i:%02i", hours,
else if (hours > 0)
snprintf(p, n, "%i:%02i:%02i", hours,
minutes, seconds);
else
snprintf(p, n, "%i:%02i", minutes,

148
src/mpd.c
View File

@ -9,14 +9,14 @@ void update_mpd()
{
struct information *current_info = &info;
current_info->conn =
mpd_newConnection(current_info->mpd.host,
current_info->mpd.port, 10);
mpd_newConnection(current_info->mpd.host,
current_info->mpd.port, 10);
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
@ -43,7 +43,7 @@ void update_mpd()
mpd_closeConnection(current_info->conn);
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
@ -71,6 +71,16 @@ void update_mpd()
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
strcpy(current_info->mpd.artist, "Stopped");
strcpy(current_info->mpd.album, "Stopped");
strcpy(current_info->mpd.title, "Stopped");
}
if (status->state == MPD_STATUS_STATE_PAUSE) {
current_info->mpd.status = "Paused";
@ -81,74 +91,84 @@ void update_mpd()
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
}
if (status->state == MPD_STATUS_STATE_PLAY ||
status->state == MPD_STATUS_STATE_PAUSE) {
current_info->mpd.bitrate = status->bitRate;
current_info->mpd.progress =
(float) status->elapsedTime / status->totalTime;
current_info->mpd.elapsed = status->elapsedTime;
current_info->mpd.length = status->totalTime;
}
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
return;
}
mpd_nextListOkCommand(current_info->conn);
while ((entity = mpd_getNextInfoEntity(current_info->conn))) {
mpd_Song *song = entity->info.song;
if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) {
mpd_freeInfoEntity(entity);
continue;
}
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (song->artist) {
strcpy(current_info->mpd.artist, song->artist);
} else {
strcpy(current_info->mpd.artist, "Unknown");
}
if (song->album) {
strcpy(current_info->mpd.album, song->album);
} else {
strcpy(current_info->mpd.album, "Unknown");
}
if (song->title) {
strcpy(current_info->mpd.title, song->title);
} else {
strcpy(current_info->mpd.title, "Unknown");
}
if (entity != NULL) {
mpd_freeInfoEntity(entity);
}
}
if (entity != NULL) {
mpd_freeInfoEntity(entity);
strcpy(current_info->mpd.artist, "Unknown");
strcpy(current_info->mpd.album, "Unknown");
strcpy(current_info->mpd.title, "Unknown");
}
if (status->state == MPD_STATUS_STATE_PLAY ||
status->state == MPD_STATUS_STATE_PAUSE) {
current_info->mpd.bitrate = status->bitRate;
current_info->mpd.progress =
(float) status->elapsedTime / status->totalTime;
current_info->mpd.elapsed = status->elapsedTime;
current_info->mpd.length = status->totalTime;
}
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
return;
}
mpd_finishCommand(current_info->conn);
if (current_info->conn->error) {
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
return;
}
mpd_freeStatus(status);
mpd_closeConnection(current_info->conn);
mpd_closeConnection(current_info->conn);
return;
}
mpd_nextListOkCommand(current_info->conn);
while ((entity = mpd_getNextInfoEntity(current_info->conn))) {
mpd_Song *song = entity->info.song;
if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) {
mpd_freeInfoEntity(entity);
continue;
}
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (song->artist) {
strcpy(current_info->mpd.artist, song->artist);
} else {
strcpy(current_info->mpd.artist, "Unknown");
}
if (song->album) {
strcpy(current_info->mpd.album, song->album);
} else {
strcpy(current_info->mpd.album, "Unknown");
}
if (song->title) {
strcpy(current_info->mpd.title, song->title);
} else {
strcpy(current_info->mpd.title, "Unknown");
}
if (entity != NULL) {
mpd_freeInfoEntity(entity);
}
}
if (entity != NULL) {
mpd_freeInfoEntity(entity);
}
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
return;
}
mpd_finishCommand(current_info->conn);
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
return;
}
mpd_freeStatus(status);
mpd_closeConnection(current_info->conn);
}

View File

@ -30,7 +30,7 @@ static struct process *find_process(pid_t pid)
static struct process *new_process(int p)
{
struct process *process;
process = malloc(sizeof(struct process));
process = (struct process*)malloc(sizeof(struct process));
/*
* Do stitching necessary for doubly linked list