audacious support added
[monky] / src / conky.c
index c8d3c39..4fa5625 100644 (file)
@@ -226,6 +226,7 @@ static int gap_x, gap_y;
 
 /* border */
 static int draw_borders;
+static int draw_graph_borders;
 static int stippled_borders;
 
 static int draw_shades, draw_outline;
@@ -891,6 +892,20 @@ enum text_object_type {
        OBJ_mpd_track,
        OBJ_mpd_percent,
 #endif
+#ifdef AUDACIOUS
+        OBJ_audacious_status,
+        OBJ_audacious_song,
+        OBJ_audacious_song_length,
+        OBJ_audacious_song_length_seconds,
+        OBJ_audacious_song_length_frames,
+        OBJ_audacious_song_output_length,
+        OBJ_audacious_song_output_length_seconds,
+        OBJ_audacious_song_output_length_frames,
+        OBJ_audacious_song_bitrate,
+        OBJ_audacious_song_frequency,
+        OBJ_audacious_song_channels,
+        OBJ_audacious_bar,
+#endif
 #ifdef BMPX
        OBJ_bmpx_title,
        OBJ_bmpx_artist,
@@ -914,6 +929,7 @@ enum text_object_type {
        OBJ_infopipe_channels,
        OBJ_infopipe_title,
        OBJ_infopipe_file,
+       OBJ_infopipe_bar,
 #endif
 #ifdef TCP_PORT_MONITOR
        OBJ_tcp_portmon,
@@ -1809,18 +1825,40 @@ int a = stippled_borders, b = 1;
         (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
        END
 #endif
+#ifdef AUDACIOUS
+        OBJ(audacious_status, INFO_AUDACIOUS) END
+        OBJ(audacious_song, INFO_AUDACIOUS) END
+        OBJ(audacious_song_length, INFO_AUDACIOUS) END
+        OBJ(audacious_song_length_seconds, INFO_AUDACIOUS) END
+        OBJ(audacious_song_length_frames, INFO_AUDACIOUS) END
+        OBJ(audacious_song_output_length, INFO_AUDACIOUS) END
+        OBJ(audacious_song_output_length_seconds, INFO_AUDACIOUS) END
+        OBJ(audacious_song_output_length_frames, INFO_AUDACIOUS) END
+        OBJ(audacious_song_bitrate, INFO_AUDACIOUS) END
+        OBJ(audacious_song_frequency, INFO_AUDACIOUS) END
+        OBJ(audacious_song_channels, INFO_AUDACIOUS) END
+        OBJ(audacious_bar, INFO_AUDACIOUS)
+            (void) scan_bar(arg, &obj->a, &obj->b);
+        END
+#endif
 #ifdef BMPX
        OBJ(bmpx_title, INFO_BMPX)
+               memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
        END
        OBJ(bmpx_artist, INFO_BMPX)
+               memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
        END
        OBJ(bmpx_album, INFO_BMPX)
+               memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
        END
        OBJ(bmpx_track, INFO_BMPX)
+               memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
        END
        OBJ(bmpx_uri, INFO_BMPX)
+               memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
        END
        OBJ(bmpx_bitrate, INFO_BMPX)
+               memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
        END
 #endif
 #ifdef INFOPIPE
@@ -1838,6 +1876,9 @@ int a = stippled_borders, b = 1;
        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) 
@@ -3094,6 +3135,48 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                               255.0f));
                        }
 #endif
+#ifdef AUDACIOUS
+                        OBJ(audacious_status) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
+                        }
+                        OBJ(audacious_song) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG]);
+                       }
+                        OBJ(audacious_song_length) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH]);
+                       }
+                        OBJ(audacious_song_length_seconds) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]);
+                       }
+                        OBJ(audacious_song_length_frames) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_FRAMES]);
+                       }
+                        OBJ(audacious_song_output_length) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH]);
+                       }
+                        OBJ(audacious_song_output_length_seconds) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]);
+                       }
+                        OBJ(audacious_song_output_length_frames) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES]);
+                       }
+                        OBJ(audacious_song_bitrate) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_BITRATE]);
+                       }
+                        OBJ(audacious_song_frequency) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_FREQUENCY]);
+                       }
+                        OBJ(audacious_song_channels) {
+                           snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
+                       }
+                        OBJ(audacious_bar) {
+                            double progress;
+                            progress= atof(cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]) /
+                                      atof(cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]);
+                            new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
+
+                       }
+#endif
 #ifdef BMPX
                        OBJ(bmpx_title) {
                                snprintf(p, p_max_size, "%s", cur->bmpx.title);
@@ -3157,6 +3240,12 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                         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
@@ -3218,7 +3307,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
 
 
                        OBJ(tail) {
-                               if (current_update_time -obj->data.tail.last_update >= obj->data.tail.interval) {
+                               if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
+                                                       snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
+                               } else {
                                        obj->data.tail.last_update = current_update_time;
                                        FILE *fp;
                                        int i;
@@ -3267,10 +3358,12 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                                        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 {
                                                        strcpy(obj->data.tail.buffer, "Logfile Empty");
+                                                       snprintf(p, p_max_size, "Logfile Empty");
                                                }  /* if readlines */
                                        } /*  fp == NULL  */
                                } /* if cur_upd_time >= */
@@ -3279,7 +3372,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
 
                        }
                        OBJ(head) {
-                               if (current_update_time -obj->data.tail.last_update >= obj->data.tail.interval) {
+                               if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
+                                                       snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
+                               } else {
                                        obj->data.tail.last_update = current_update_time;
                                        FILE *fp;
                                        tailstring *head = NULL;
@@ -3314,8 +3409,10 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                                        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 {
                                                        strcpy(obj->data.tail.buffer, "Logfile Empty");
+                                                       snprintf(p, p_max_size, "Logfile Empty");
                                                } /* if readlines > 0 */
                                        } /* if fp == null */
                                } /* cur_upd_time >= */
@@ -3983,15 +4080,10 @@ static void draw_line(char *s)
                                                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,
@@ -4672,8 +4764,9 @@ static void set_default_configurations(void)
        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;
@@ -4897,6 +4990,9 @@ else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
                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);
                }
@@ -5469,6 +5565,22 @@ int main(int argc, char **argv)
                ERR("error setting signal handler: %s", strerror(errno) );
        }
 
+#ifdef AUDACIOUS
+       /* joinable thread for audacious activity */
+        pthread_attr_init(&info.audacious.thread_attr);
+       pthread_attr_setdetachstate(&info.audacious.thread_attr, PTHREAD_CREATE_JOINABLE);
+       /* init mutexex */
+       pthread_mutex_init(&info.audacious.item_mutex, NULL);
+       pthread_mutex_init(&info.audacious.runnable_mutex, NULL);
+       /* init runnable condition for worker thread */
+       pthread_mutex_lock(&info.audacious.runnable_mutex);
+       info.audacious.runnable=1;
+       pthread_mutex_unlock(&info.audacious.runnable_mutex);
+       if (pthread_create(&info.audacious.thread, &info.audacious.thread_attr, audacious_thread_func, NULL))
+       {
+           CRIT_ERR("unable to create audacious thread!");
+       }
+#endif
 #ifdef INFOPIPE
        /* joinable thread for infopipe activity */
         pthread_attr_init(&info.infopipe.thread_attr);
@@ -5487,7 +5599,22 @@ int main(int argc, char **argv)
 #endif
 
        main_loop();
-       
+
+#ifdef AUDACIOUS
+        /* signal audacious worker thread to terminate */
+        pthread_mutex_lock(&info.audacious.runnable_mutex);
+        info.audacious.runnable=0;
+        pthread_mutex_unlock(&info.audacious.runnable_mutex);
+        /* destroy thread attribute and wait for thread */
+        pthread_attr_destroy(&info.audacious.thread_attr);
+        if (pthread_join(info.audacious.thread, NULL))
+        {
+            ERR("error joining audacious thread");
+        }
+        /* destroy mutexes */
+        pthread_mutex_destroy(&info.audacious.item_mutex);
+        pthread_mutex_destroy(&info.audacious.runnable_mutex);
+#endif 
 #ifdef INFOPIPE
        /* signal infopipe worker thread to terminate */
        pthread_mutex_lock(&info.infopipe.runnable_mutex);