static void set_font();
-
int addfont(const char *data_in)
{
if (font_count > MAX_FONTS) {
/* border */
static int draw_borders;
+static int draw_graph_borders;
static int stippled_borders;
static int draw_shades, draw_outline;
OBJ_mpd_track,
OBJ_mpd_percent,
#endif
+#ifdef BMPX
+ OBJ_bmpx_title,
+ OBJ_bmpx_artist,
+ OBJ_bmpx_album,
+ OBJ_bmpx_track,
+ OBJ_bmpx_uri,
+ OBJ_bmpx_bitrate,
+#endif
+#ifdef INFOPIPE
+ OBJ_infopipe_protocol,
+ OBJ_infopipe_version,
+ OBJ_infopipe_status,
+ OBJ_infopipe_playlist_tunes,
+ OBJ_infopipe_playlist_currtune,
+ OBJ_infopipe_usec_position,
+ OBJ_infopipe_position,
+ OBJ_infopipe_usec_time,
+ OBJ_infopipe_time,
+ OBJ_infopipe_bitrate,
+ OBJ_infopipe_frequency,
+ OBJ_infopipe_channels,
+ OBJ_infopipe_title,
+ OBJ_infopipe_file,
+ OBJ_infopipe_bar,
+#endif
#ifdef TCP_PORT_MONITOR
OBJ_tcp_portmon,
#endif
static unsigned int text_object_count;
static struct text_object *text_objects;
+static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
return obj;
}
-/* new_text_object() allocates a new zeroed text_object */
-static struct text_object *new_text_object()
-{
- text_object_count++;
- text_objects = (struct text_object *) realloc(text_objects,
- sizeof(struct
- text_object) *
- text_object_count);
- memset(&text_objects[text_object_count - 1], 0,
- sizeof(struct text_object));
-
- return &text_objects[text_object_count - 1];
-}
-
#ifdef MLDONKEY
void ml_cleanup()
{
free(objs[i].data.tail.logfile);
free(objs[i].data.tail.buffer);
break;
- case OBJ_text:
- case OBJ_font:
+ case OBJ_text: case OBJ_font:
free(objs[i].data.s);
break;
case OBJ_exec:
case OBJ_mpd_status:
case OBJ_mpd_host:
#endif
+#ifdef BMPX
+ case OBJ_bmpx_title:
+ case OBJ_bmpx_artist:
+ case OBJ_bmpx_album:
+ case OBJ_bmpx_track:
+ case OBJ_bmpx_uri:
+ case OBJ_bmpx_bitrate:
+#endif
case OBJ_pre_exec:
case OBJ_battery:
free(objs[i].data.s);
}
}
+
/* construct_text_object() creates a new text_object */
static struct text_object *construct_text_object(const char *s, const char *arg)
{
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
obj->data.s = strdup(buf);
- } else {
- obj->data.execi.cmd = strdup(arg + n);
- }
+ } else {
+ obj->data.execi.cmd = strdup(arg + n);
+ }
END OBJ(execi, 0) unsigned int n;
if (!arg
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
END
#endif
+#ifdef BMPX
+ OBJ(bmpx_title, INFO_BMPX)
+ END
+ OBJ(bmpx_artist, INFO_BMPX)
+ END
+ OBJ(bmpx_album, INFO_BMPX)
+ END
+ OBJ(bmpx_track, INFO_BMPX)
+ END
+ OBJ(bmpx_uri, INFO_BMPX)
+ END
+ OBJ(bmpx_bitrate, INFO_BMPX)
+ END
+#endif
+#ifdef INFOPIPE
+ OBJ(infopipe_protocol, INFO_INFOPIPE) END
+ OBJ(infopipe_version, INFO_INFOPIPE) END
+ OBJ(infopipe_status, INFO_INFOPIPE) END
+ OBJ(infopipe_playlist_tunes, INFO_INFOPIPE) END
+ OBJ(infopipe_playlist_currtune, INFO_INFOPIPE) END
+ OBJ(infopipe_usec_position, INFO_INFOPIPE) END
+ OBJ(infopipe_position, INFO_INFOPIPE) END
+ OBJ(infopipe_usec_time, INFO_INFOPIPE) END
+ OBJ(infopipe_time, INFO_INFOPIPE) END
+ OBJ(infopipe_bitrate, INFO_INFOPIPE) END
+ OBJ(infopipe_frequency, INFO_INFOPIPE) END
+ OBJ(infopipe_channels, INFO_INFOPIPE) END
+ OBJ(infopipe_title, INFO_INFOPIPE) END
+ OBJ(infopipe_file, INFO_INFOPIPE) END
+ OBJ(infopipe_bar, INFO_INFOPIPE)
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ END
+#endif
#ifdef TCP_PORT_MONITOR
OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
int argc, port_begin, port_end, item, connection_index;
return obj;
}
-/* append_text() appends text to last text_object if it's text, if it isn't
- * it creates a new text_object [DEPRECATED]
-*/
-static void append_text(const char *s)
-{
- struct text_object *obj;
-
- if (s == NULL || *s == '\0')
- return;
-
- obj = text_object_count ? &text_objects[text_object_count - 1] : 0;
-
- /* create a new text object? */
- if (!obj || obj->type != OBJ_text) {
- obj = new_text_object();
- obj->type = OBJ_text;
- obj->data.s = strdup(s);
- } else {
- /* append */
- obj->data.s = (char *) realloc(obj->data.s,
- strlen(obj->data.s) +
- strlen(s) + 1);
- strcat(obj->data.s, s);
- }
-}
-
-
static struct text_object_list *extract_variable_text_internal(const char *p)
{
struct text_object_list *retval;
obj, sizeof(struct text_object));
free(obj);
}
-
-
}
continue;
} else {
free(obj);
}
}
-
}
-
p++;
}
-
obj = create_plain_text(s);
if(obj != NULL) {
// allocate memory for the object
- retval->text_objects = realloc(retval->text_objects,
+ retval->text_objects = realloc(retval->text_objects,
sizeof(struct text_object) * (retval->text_object_count+1));
// assign the new object to the end of the list.
memcpy(&retval->text_objects[retval->text_object_count++],
list = extract_variable_text_internal(p);
text_objects = list->text_objects;
- text_object_count = list->text_object_count;
+ text_object_count = list->text_object_count;
free(list);
return;
}
+void parse_conky_vars(char * text, char * p, struct information *cur) {
+ struct text_object_list *object_list = extract_variable_text_internal(text);
+ generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
+ free(object_list);
+}
static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
{
}
OBJ(exec) {
- char *output = p;
FILE *fp = popen(obj->data.s, "r");
int length = fread(p, 1, p_max_size, fp);
(void) pclose(fp);
-
- output[length] = '\0';
+
+ /*output[length] = '\0';
if (length > 0 && output[length - 1] == '\n') {
output[length - 1] = '\0';
- }
+ }*/
+ p[length] = '\0';
+ if (length > 0 && p[length - 1] == '\n') {
+ p[length - 1] = '\0';
+ }
- struct text_object_list *object_list = extract_variable_text_internal(output);
- generate_text_internal(p, length, object_list->text_objects, object_list->text_object_count, cur);
- free(object_list);
-/* DaC
- p[n2] = '\0';
- if (n2 && p[n2 - 1] == '\n')
- p[n2 - 1] = '\0';
-
- while (*p2) {
- if (*p2 == '\001')
- *p2 = ' ';
- p2++;
- }
-*/
+ //parse_conky_vars(output, p, cur);
}
OBJ(execbar) {
char *p2 = p;
}
OBJ(execibar) {
- if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
new_bar(p, 0, 4, (int) obj->f);
} else {
char *p2 = p;
}
}
OBJ(execigraph) {
- if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
} else {
char *p2 = p;
}
OBJ(execi) {
- if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
- snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
+ snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
} else {
- char *output = obj->data.execi.buffer;
- FILE *fp = popen(obj->data.execi.cmd, "r");
- int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
- (void) pclose(fp);
-
- output[length] = '\0';
- if (length > 0 && output[length - 1] == '\n')
- output[length - 1] = '\0';
-
- struct text_object_list *object_list = extract_variable_text_internal(output);
- generate_text_internal(p, length, object_list->text_objects, object_list->text_object_count, cur);
- free(object_list);
-
- /*
- char *p2 = obj->data.execi.buffer;
+ char *output = obj->data.execi.buffer;
FILE *fp = popen(obj->data.execi.cmd, "r");
- int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
+ //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
+ int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
(void) pclose(fp);
-
- p2[n2] = '\0';
- if (n2 && p2[n2 - 1] == '\n')
- p2[n2 - 1] = '\0';
-
- while (*p2) {
- if (*p2 == '\001') {
- *p2 = ' ';
- } else if(*p2 == '$') {
- //memset(*t, 0, sizeof(struct text_object));
- }
- p2++;
+
+ output[length] = '\0';
+ if (length > 0 && output[length - 1] == '\n') {
+ output[length - 1] = '\0';
}
-
- snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
- obj->data.execi.last_update = current_update_time;*/
+ obj->data.execi.last_update = current_update_time;
+ snprintf(p, p_max_size, "%s", output);
}
+ //parse_conky_vars(output, p, cur);
}
OBJ(texeci) {
static int running = 0;
- if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
} else {
static pthread_t execthread;
+ if (running) {
+ pthread_join( execthread, NULL);
+ running = 0;
+ }
if (!running) {
running = 1;
pthread_create( &execthread, NULL, (void*)threaded_exec, (void*) obj);
pthread_mutex_lock( &mutex1 );
obj->data.execi.last_update = current_update_time;
pthread_mutex_unlock( &mutex1 );
- } else {
- pthread_join( execthread, NULL);
- running = 0;
}
snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
}
+ //parse_conky_vars(obj->data.execi.buffer, p, cur);
}
#endif
OBJ(fs_bar) {
255.0f));
}
#endif
+#ifdef BMPX
+ OBJ(bmpx_title) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.title);
+ }
+ OBJ(bmpx_artist) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.artist);
+ }
+ OBJ(bmpx_album) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.album);
+ }
+ OBJ(bmpx_uri) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.uri);
+ }
+ OBJ(bmpx_track) {
+ snprintf(p, p_max_size, "%i", cur->bmpx.track);
+ }
+ OBJ(bmpx_bitrate) {
+ snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
+ }
+#endif
+#ifdef INFOPIPE
+ OBJ(infopipe_protocol) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PROTOCOL]);
+ }
+ OBJ(infopipe_version) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_VERSION]);
+ }
+ OBJ(infopipe_status) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_STATUS]);
+ }
+ OBJ(infopipe_playlist_tunes) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_TUNES]);
+ }
+ OBJ(infopipe_playlist_currtune) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_CURRTUNE]);
+ }
+ OBJ(infopipe_usec_position) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_POSITION]);
+ }
+ OBJ(infopipe_position) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_POSITION]);
+ }
+ OBJ(infopipe_usec_time) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_TIME]);
+ }
+ OBJ(infopipe_time) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TIME]);
+ }
+ OBJ(infopipe_bitrate) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_BITRATE]);
+ }
+ OBJ(infopipe_frequency) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FREQUENCY]);
+ }
+ OBJ(infopipe_channels) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_CHANNELS]);
+ }
+ OBJ(infopipe_title) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TITLE]);
+ }
+ OBJ(infopipe_file) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FILE]);
+ }
+ OBJ(infopipe_bar) {
+ double progress;
+ progress= atof(cur->infopipe.items[INFOPIPE_USEC_POSITION]) /
+ atof(cur->infopipe.items[INFOPIPE_USEC_TIME]);
+ new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
+ }
+#endif
OBJ(top) {
if (obj->data.top.type == TOP_NAME
&& obj->data.top.num >= 0
}
-
- /*
- * I'm tired of everything being packed in
- * pee
- * poop
- */
-
-
OBJ(tail) {
- if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
- snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
- } else {
+ if (current_update_time -obj->data.tail.last_update >= obj->data.tail.interval) {
obj->data.tail.last_update = current_update_time;
FILE *fp;
int i;
if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
}
- snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
freetail(freetmp);
- }
- else {
+ } else {
strcpy(obj->data.tail.buffer, "Logfile Empty");
- snprintf(p, p_max_size, "Logfile Empty");
- }
- }
- }
+ } /* if readlines */
+ } /* fp == NULL */
+ } /* if cur_upd_time >= */
+
+ //parse_conky_vars(obj->data.tail.buffer, p, cur);
+
}
OBJ(head) {
- if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
- snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
- } else {
+ if (current_update_time -obj->data.tail.last_update >= obj->data.tail.interval) {
obj->data.tail.last_update = current_update_time;
FILE *fp;
tailstring *head = NULL;
fp = fopen(obj->data.tail.logfile, "rt");
if (fp == NULL) {
ERR("head logfile failed to open");
- }
- else {
+ } else {
obj->data.tail.readlines = 0;
while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
addtail(&head, obj->data.tail.buffer);
if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
}
- snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
- }
- else {
+ } else {
strcpy(obj->data.tail.buffer, "Logfile Empty");
- snprintf(p, p_max_size, "Logfile Empty");
- }
- }
- }
+ } /* if readlines > 0 */
+ } /* if fp == null */
+ } /* cur_upd_time >= */
+
+ //parse_conky_vars(obj->data.tail.buffer, p, cur);
+
}
#ifdef TCP_PORT_MONITOR
OBJ(tcp_portmon)
static void generate_text()
{
- unsigned int n;
struct information *cur = &info;
char *p;
update_stuff(cur);
+ /* add things to the buffer */
+
/* generate text */
- n = TEXT_BUFFER_SIZE * 4 - 2;
p = text_buffer;
- generate_text_internal(p, n, text_objects, text_object_count, cur);
+ generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
if (stuff_in_upper_case) {
char *p;
width_of_s = get_string_width(s);
if (out_to_console) {
printf("%s\n", s);
+ fflush(stdout); /* output immediately, don't buffer */
}
/* daemon_run(s); the daemon can be called here, but we need to have a buffer in daemon_run() and we need to tell it when everything is ready to be sent */
memset(tmpstring1,0,TEXT_BUFFER_SIZE);
w = text_start_x + text_width - cur_x - 1;
if (w < 0)
w = 0;
- XSetLineAttributes(display,
- window.gc, 1,
- LineSolid,
- CapButt,
- JoinMiter);
- XDrawRectangle(display,
- window.drawable,
- window.gc, cur_x,
- by, w, h);
+ if (draw_graph_borders) {
+ XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
+ XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
+ }
XSetLineAttributes(display,
window.gc, 1,
LineSolid,
default_fg_color = WhitePixel(display, screen);
default_bg_color = BlackPixel(display, screen);
default_out_color = BlackPixel(display, screen);
- draw_borders = 0;
draw_shades = 1;
+ draw_borders = 0;
+ draw_graph_borders = 1;
draw_outline = 0;
set_first_font("6x10");
gap_x = 5;
CONF("draw_borders") {
draw_borders = string_to_bool(value);
}
+ CONF("draw_graph_borders") {
+ draw_graph_borders = string_to_bool(value);
+ }
CONF("draw_shades") {
draw_shades = string_to_bool(value);
}
use_xft = string_to_bool(value);
}
CONF("font") {
- if (!use_xft) {
- if (value) {
- set_first_font(value);
- } else
- CONF_ERR;
- }
+ if (value) {
+ set_first_font(value);
+ } else
+ CONF_ERR;
}
CONF("xftalpha") {
if (value && font_count >= 0)
}
CONF("font") {
#endif
- if (value) {
- set_first_font(value);
- } else
- CONF_ERR;
+ if (use_xft) {
+ if (value) {
+ set_first_font(value);
+ } else
+ CONF_ERR;
+ }
}
CONF("gap_x") {
if (value)
ERR("error setting signal handler: %s", strerror(errno) );
}
+#ifdef INFOPIPE
+ /* joinable thread for infopipe activity */
+ pthread_attr_init(&info.infopipe.thread_attr);
+ pthread_attr_setdetachstate(&info.infopipe.thread_attr, PTHREAD_CREATE_JOINABLE);
+ /* init mutexex */
+ pthread_mutex_init(&info.infopipe.item_mutex, NULL);
+ pthread_mutex_init(&info.infopipe.runnable_mutex, NULL);
+ /* init runnable condition for worker thread */
+ pthread_mutex_lock(&info.infopipe.runnable_mutex);
+ info.infopipe.runnable=1;
+ pthread_mutex_unlock(&info.infopipe.runnable_mutex);
+ if (pthread_create(&info.infopipe.thread, &info.infopipe.thread_attr, infopipe_thread_func, NULL))
+ {
+ CRIT_ERR("unable to create infopipe thread!");
+ }
+#endif
+
main_loop();
+
+#ifdef INFOPIPE
+ /* signal infopipe worker thread to terminate */
+ pthread_mutex_lock(&info.infopipe.runnable_mutex);
+ info.infopipe.runnable=0;
+ pthread_mutex_unlock(&info.infopipe.runnable_mutex);
+ /* destroy thread attribute and wait for thread */
+ pthread_attr_destroy(&info.infopipe.thread_attr);
+ if (pthread_join(info.infopipe.thread, NULL))
+ {
+ ERR("error joining infopipe thread");
+ }
+ /* destroy mutexes */
+ pthread_mutex_destroy(&info.infopipe.item_mutex);
+ pthread_mutex_destroy(&info.infopipe.runnable_mutex);
+#endif
return 0;
}