2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
28 #include <X11/Xutil.h>
29 #include <X11/extensions/Xdamage.h>
34 #include <sys/types.h>
36 #include <netinet/in.h>
46 #define CONFIG_FILE "$HOME/.conkyrc"
47 #define MAIL_FILE "$MAIL"
48 #define MAX_IF_BLOCK_DEPTH 5
50 /* #define SIGNAL_BLOCKING */
51 #undef SIGNAL_BLOCKING
53 static void print_version()
55 printf("Conky %s compiled %s for %s\n",
56 VERSION, BUILD_DATE, BUILD_ARCH);
59 "\nCompiled in features:\n\n"
66 " * Xdamage extension\n"
67 # endif /* HAVE_XDAMAGE */
69 " * Xdbe extension (double buffer)\n"
70 # endif /* HAVE_XDBE */
72 "\n Music detection:\n"
81 #endif /* AUDACIOUS */
94 "\n General features:\n"
95 #ifdef TCP_PORT_MONITOR
97 #endif /* TCP_PORT_MONITOR */
100 #endif /* MLDONKEY */
118 static int text_start_x, text_start_y; /* text start position in window */
119 static int text_width, text_height;
134 char name[TEXT_BUFFER_SIZE];
144 static int selected_font = 0;
145 static int font_count = -1;
146 struct font_list *fonts = NULL;
150 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
151 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
152 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
153 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
157 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
158 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
159 #define font_descent() fonts[selected_font].font->max_bounds.descent
163 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
166 static void set_font();
168 int addfont(const char *data_in)
170 if (font_count > MAX_FONTS) {
171 CRIT_ERR("you don't need that many fonts, sorry.");
174 if (font_count == 0) {
178 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
182 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
184 CRIT_ERR("realloc in addfont");
186 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
187 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
189 fonts[font_count].font_alpha = 0xffff;
192 CRIT_ERR("Oops...looks like something overflowed in addfont().");
197 void set_first_font(const char *data_in)
199 if (font_count < 0) {
200 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
205 if (strlen(data_in) > 1) {
206 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
208 fonts[0].font_alpha = 0xffff;
216 for (i=0;i<=font_count;i++) {
219 XftFontClose(display, fonts[i].xftfont);
223 XFreeFont(display, fonts[i].font);
230 set_first_font("6x10");
234 static void load_fonts()
237 for (i=0; i <= font_count; i++) {
241 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
242 XftFontClose(display, fonts[i].xftfont);
244 if ((fonts[i].xftfont =
245 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
248 ERR("can't load Xft font '%s'", fonts[i].name);
249 if ((fonts[i].xftfont =
250 XftFontOpenName(display, screen,
251 "courier-12")) != NULL)
254 ERR("can't load Xft font '%s'", "courier-12");
256 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
257 CRIT_ERR("can't load font '%s'", "fixed");
264 /* load normal font */
265 /* if (fonts[i].font != NULL)
266 XFreeFont(display, fonts[i].font);*/
268 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
269 ERR("can't load font '%s'", fonts[i].name);
270 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
271 CRIT_ERR("can't load font '%s'", "fixed");
272 printf("loaded fixed?\n");
280 /* default config file */
281 static char *current_config;
283 /* set to 1 if you want all text to be in uppercase */
284 static unsigned int stuff_in_upper_case;
286 /* Update interval */
287 static double update_interval;
289 /* Run how many times? */
290 static unsigned long total_run_times;
293 static int fork_to_background;
295 static int cpu_avg_samples, net_avg_samples;
299 /* Always on bottom */
300 static int on_bottom;
302 /* Position on the screen */
303 static int text_alignment;
304 static int gap_x, gap_y;
307 static int draw_borders;
308 static int draw_graph_borders;
309 static int stippled_borders;
311 static int draw_shades, draw_outline;
313 static int border_margin, border_width;
315 static long default_fg_color, default_bg_color, default_out_color;
317 /* create own window or draw stuff to root? */
318 static int set_transparent = 0;
322 static int own_window = 0;
323 static int background_colour = 0;
324 /* fixed size/pos is set if wm/user changes them */
325 static int fixed_size = 0, fixed_pos = 0;
328 static int minimum_width, minimum_height;
329 static int maximum_width;
334 #define CODEPAGE_LENGTH 20
337 char iconv_converting;
338 static iconv_t **iconv_cd = 0;
340 int register_iconv(iconv_t *new_iconv)
343 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
345 iconv_cd = malloc(sizeof(iconv_t *));
348 CRIT_ERR("Out of memory");
350 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
351 if (!iconv_cd[iconv_count]) {
352 CRIT_ERR("Out of memory");
354 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
359 void free_iconv(void)
363 for (i = iconv_count; i < 0; i++) {
379 /* no buffers in used memory? */
382 /* pad percentages to decimals? */
383 static int pad_percents = 0;
385 #ifdef TCP_PORT_MONITOR
386 tcp_port_monitor_collection_args_t tcp_port_monitor_collection_args;
387 tcp_port_monitor_args_t tcp_port_monitor_args;
390 /* Text that is shown */
391 static char original_text[] =
392 "$nodename - $sysname $kernel on $machine\n"
394 "${color grey}Uptime:$color $uptime\n"
395 "${color grey}Frequency (in MHz):$color $freq\n"
396 "${color grey}Frequency (in GHz):$color $freq_g\n"
397 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
398 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
399 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
400 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
402 "${color grey}File systems:\n"
403 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
404 "${color grey}Networking:\n"
405 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
408 "${color grey}SETI@Home Statistics:\n"
409 "${color grey}Seti Unit Number:$color $seti_credit\n"
410 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
413 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
414 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
417 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
418 "Progress: $xmms2_bar\n"
420 "${color grey}Name PID CPU% MEM%\n"
421 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
422 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
423 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
424 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
425 "${tail /var/log/Xorg.0.log 3}";
427 static char *text = original_text;
430 static int total_updates;
433 static int blockdepth = 0;
434 static int if_jumped = 0;
435 static int blockstart[MAX_IF_BLOCK_DEPTH];
437 int check_mount(char *s)
439 #if defined(__linux__)
441 FILE *mtab = fopen("/etc/mtab", "r");
443 char buf1[256], buf2[128];
444 while (fgets(buf1, 256, mtab)) {
445 sscanf(buf1, "%*s %128s", buf2);
446 if (!strcmp(s, buf2)) {
453 ERR("Could not open mtab");
456 #elif defined(__FreeBSD__)
457 struct statfs *mntbuf;
460 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
461 for (i = mntsize - 1; i >= 0; i--)
462 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
471 static inline int calc_text_width(const char *s, int l)
477 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
479 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
485 return XTextWidth(fonts[selected_font].font, s, l);
490 /* formatted text to render on screen, generated in generate_text(),
491 * drawn in draw_stuff() */
493 static char text_buffer[TEXT_BUFFER_SIZE * 4];
495 /* special stuff in text_buffer */
497 #define SPECIAL_CHAR '\x01'
516 static struct special_t {
526 unsigned long first_colour; // for graph gradient
527 unsigned long last_colour;
530 static int special_count;
532 static int special_index; /* used when drawing */
535 #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? */
537 static struct special_t *new_special(char *buf, int t)
539 if (special_count >= 512)
540 CRIT_ERR("too many special things in text");
542 buf[0] = SPECIAL_CHAR;
544 specials[special_count].type = t;
545 return &specials[special_count++];
548 typedef struct tailstring_list {
549 char data[TEXT_BUFFER_SIZE];
550 struct tailstring_list *next;
551 struct tailstring_list *first;
554 void addtail(tailstring ** head, char *data_in)
557 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
563 tmp->first = (*head)->first;
565 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
570 void freetail(tailstring * head)
573 while (head != NULL) {
580 void freelasttail(tailstring * head)
582 tailstring * tmp = head;
584 if (tmp->next == head->first) {
591 while(head != NULL && tmp != NULL) {
597 static void new_bar(char *buf, int w, int h, int usage)
599 struct special_t *s = new_special(buf, BAR);
600 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
605 static const char *scan_bar(const char *args, int *w, int *h)
607 *w = 0; /* zero width means all space that is available */
609 /* bar's argument is either height or height,width */
612 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
613 sscanf(args, "%d %n", h, &n);
620 static char *scan_font(const char *args)
622 if (args && sizeof(args) < 127) {
629 static void new_font(char *buf, char * args) {
631 struct special_t *s = new_special(buf, FONT);
632 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
633 int tmp = selected_font;
634 selected_font = s->font_added = addfont(args);
639 struct special_t *s = new_special(buf, FONT);
640 int tmp = selected_font;
641 selected_font = s->font_added = 0;
648 inline void graph_append(struct special_t *graph, double f)
650 if (!graph->scaled && f > graph->graph_scale) {
651 f = graph->graph_scale;
655 graph->graph_scale = 1;
657 graph->graph[0] = f; /* add new data */
658 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
659 graph->graph[i] = graph->graph[i - 1];
660 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
661 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
666 short colour_depth = 0;
667 void set_up_gradient();
669 /* precalculated: 31/255, and 63/255 */
670 #define CONST_8_TO_5_BITS 0.12156862745098
671 #define CONST_8_TO_6_BITS 0.247058823529412
673 /* adjust color values depending on color depth*/
674 static unsigned int adjust_colors(unsigned int color)
677 if (colour_depth == 0) {
680 if (colour_depth == 16) {
681 r = (color & 0xff0000) >> 16;
682 g = (color & 0xff00) >> 8;
684 color = (int)(r * CONST_8_TO_5_BITS) << 11;
685 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
686 color |= (int)(b * CONST_8_TO_5_BITS);
691 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
693 struct special_t *s = new_special(buf, GRAPH);
695 if (s->graph == NULL) {
696 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
697 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
699 s->graph_width = MAX_GRAPH_DEPTH - 2;
701 s->graph = malloc(s->graph_width * sizeof(double));
702 memset(s->graph, 0, s->graph_width * sizeof(double));
703 s->graph_scale = 100;
706 s->first_colour = adjust_colors(first_colour);
707 s->last_colour = adjust_colors(second_colour);
714 s->graph_width = s->width - 2; // subtract 2 for rectangle around
719 s->graph_scale = scale;
726 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
728 *w = 0; /* zero width means all space that is available */
732 /* graph's argument is either height or height,width */
734 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
735 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
737 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
739 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
742 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
746 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
749 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
753 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
756 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
760 if (sscanf(args, "%d,%d", h, w) < 2) {
763 sscanf(args, "%*s %d,%d", h, w);
769 static inline void new_hr(char *buf, int a)
771 new_special(buf, HORIZONTAL_LINE)->height = a;
774 static inline void new_stippled_hr(char *buf, int a, int b)
776 struct special_t *s = new_special(buf, STIPPLED_HR);
781 static inline void new_fg(char *buf, long c)
783 new_special(buf, FG)->arg = c;
786 static inline void new_bg(char *buf, long c)
788 new_special(buf, BG)->arg = c;
791 static inline void new_outline(char *buf, long c)
793 new_special(buf, OUTLINE)->arg = c;
796 static inline void new_offset(char *buf, long c)
798 new_special(buf, OFFSET)->arg = c;
801 static inline void new_voffset(char *buf, long c)
803 new_special(buf, VOFFSET)->arg = c;
806 static inline void new_alignr(char *buf, long c)
808 new_special(buf, ALIGNR)->arg = c;
811 static inline void new_alignc(char *buf, long c)
813 new_special(buf, ALIGNC)->arg = c;
816 static inline void new_goto(char *buf, long c)
818 new_special(buf, GOTO)->arg = c;
821 static inline void new_tab(char *buf, int a, int b) {
822 struct special_t *s = new_special(buf, TAB);
827 /* quite boring functions */
829 static inline void for_each_line(char *b, void (*f) (char *))
833 for (ps = b, pe = b; *pe; pe++) {
846 static void convert_escapes(char *buf)
848 char *p = buf, *s = buf;
864 /* converts from bytes to human readable format (k, M, G, T) */
865 static void human_readable(long long a, char *buf, int size)
867 // Strange conditional due to possible overflows
868 if(a / 1024 / 1024 / 1024.0 > 1024.0){
869 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
871 else if (a >= 1024 * 1024 * 1024) {
872 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
874 else if (a >= 1024 * 1024) {
875 double m = (a / 1024) / 1024.0;
877 snprintf(buf, size, "%.0fMiB", m);
879 snprintf(buf, size, "%.1fMiB", m);
880 } else if (a >= 1024)
881 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
883 snprintf(buf, size, "%LdB", a);
888 enum text_object_type {
939 #if defined(__linux__)
945 OBJ_i8k_left_fan_status,
946 OBJ_i8k_right_fan_status,
947 OBJ_i8k_left_fan_rpm,
948 OBJ_i8k_right_fan_rpm,
950 OBJ_i8k_buttons_status,
958 #endif /* __linux__ */
985 OBJ_ml_upload_counter,
986 OBJ_ml_download_counter,
987 OBJ_ml_nshared_files,
988 OBJ_ml_shared_counter,
989 OBJ_ml_tcp_upload_rate,
990 OBJ_ml_tcp_download_rate,
991 OBJ_ml_udp_upload_rate,
992 OBJ_ml_udp_download_rate,
993 OBJ_ml_ndownloaded_files,
994 OBJ_ml_ndownloading_files,
997 OBJ_running_processes,
1006 OBJ_temp1, /* i2c is used instead in these */
1026 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1028 OBJ_apm_battery_time,
1029 OBJ_apm_battery_life,
1030 #endif /* __FreeBSD__ */
1064 OBJ_xmms2_transport,
1078 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
1082 OBJ_xmms_length_seconds,
1084 OBJ_xmms_position_seconds,
1089 OBJ_xmms_playlist_length,
1090 OBJ_xmms_playlist_position,
1101 #ifdef TCP_PORT_MONITOR
1114 struct text_object {
1118 unsigned int c, d, e;
1122 char *s; /* some string */
1123 int i; /* some integer */
1124 long l; /* some other integer */
1125 unsigned int sensor;
1126 struct net_stat *net;
1128 unsigned char loadavg[3];
1129 unsigned int cpu_index;
1130 struct mail_s *mail;
1133 char *tz; /* timezone variable */
1134 char *fmt; /* time display formatting */
1178 struct thread_info_s thread_info;
1184 #ifdef TCP_PORT_MONITOR
1186 in_port_t port_range_begin; /* starting port to monitor */
1187 in_port_t port_range_end; /* ending port to monitor */
1188 int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
1189 int connection_index; /* 0 to n-1 connections. */
1200 struct text_object_list {
1201 unsigned int text_object_count;
1202 struct text_object *text_objects;
1205 static unsigned int text_object_count;
1206 static struct text_object *text_objects;
1207 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1209 #define MAX_THREADS 512 // sure whatever
1210 typedef struct thread_info_s *thread_info;
1211 static thread_info thread_list[MAX_THREADS];
1212 static int thread_count = 0;
1213 static int threads_runnable = 1;
1215 int register_thread(struct thread_info_s *new_thread)
1217 if (thread_count >= MAX_THREADS) {
1218 CRIT_ERR("Uh oh, tried to register too many threads");
1220 thread_list[thread_count] = new_thread;
1222 // may as well fix the mutex for them as well
1223 pthread_mutex_init(&(new_thread->mutex), NULL);
1225 return thread_count - 1;
1228 #define MAXDATASIZE 1000
1232 struct mail_s* parse_mail_args(char type, const char *arg) {
1233 struct mail_s *mail;
1234 mail = malloc(sizeof(struct mail_s));
1235 memset(mail, 0, sizeof(struct mail_s));
1237 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1239 ERR("Scanning IMAP args failed");
1240 } else if (type == IMAP) {
1241 ERR("Scanning POP3 args failed");
1244 // see if password needs prompting
1245 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1246 int fp = fileno(stdin);
1247 struct termios term;
1248 tcgetattr(fp, &term);
1249 term.c_lflag &= ~ECHO;
1250 tcsetattr(fp, TCSANOW, &term);
1251 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1252 scanf("%128s", mail->pass);
1254 term.c_lflag |= ECHO;
1255 tcsetattr(fp, TCSANOW, &term);
1257 // now we check for optional args
1258 tmp = strstr(arg, "-i ");
1261 sscanf(tmp, "%f", &mail->interval);
1263 mail->interval = 300; // 5 minutes
1265 tmp = strstr(arg, "-p ");
1268 sscanf(tmp, "%lu", &mail->port);
1271 mail->port = 110; // default pop3 port
1272 } else if (type == IMAP) {
1273 mail->port = 143; // default imap port
1277 tmp = strstr(arg, "-f ");
1280 sscanf(tmp, "%s", mail->folder);
1282 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1285 tmp = strstr(arg, "-e ");
1289 if (tmp[0] == '\'') {
1290 len = strstr(tmp+1, "'") - tmp - 1;
1295 strncpy(mail->command, tmp+1, len);
1297 mail->command[0] = '\0';
1303 void *imap_thread(struct mail_s* mail)
1304 { // pthreads are really beginning to piss me off
1306 int run_code = threads_runnable;
1307 update_time = get_time();
1308 int sockfd, numbytes;
1309 char recvbuf[MAXDATASIZE];
1310 char sendbuf[MAXDATASIZE];
1313 unsigned int old_unseen = UINT_MAX;
1314 unsigned int old_messages = UINT_MAX;
1316 struct sockaddr_in their_addr; // connector's address information
1317 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1318 herror("gethostbyname");
1321 while (threads_runnable == run_code && fail < 5) {
1323 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1324 sleep((int)mail->interval);
1326 update_time = get_time();
1327 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1333 their_addr.sin_family = AF_INET; // host byte order
1334 their_addr.sin_port = htons(mail->port); // short, network byte order
1335 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1336 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1339 (sockfd, (struct sockaddr *) &their_addr,
1340 sizeof(struct sockaddr)) == -1) {
1345 struct timeval timeout;
1348 timeout.tv_sec = 60; // 60 second timeout i guess
1349 timeout.tv_usec = 0;
1351 FD_SET(sockfd, &fdset);
1352 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1355 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1362 ERR("IMAP connection failed: timeout");
1366 recvbuf[numbytes] = '\0';
1367 if (strstr(recvbuf, "* OK") != recvbuf) {
1368 ERR("IMAP connection failed, probably not an IMAP server");
1372 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1373 strncat(sendbuf, mail->user,
1374 MAXDATASIZE - strlen(sendbuf) - 1);
1375 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1376 strncat(sendbuf, mail->pass,
1377 MAXDATASIZE - strlen(sendbuf) - 1);
1378 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1379 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1384 timeout.tv_sec = 60; // 60 second timeout i guess
1385 timeout.tv_usec = 0;
1387 FD_SET(sockfd, &fdset);
1388 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1391 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1398 recvbuf[numbytes] = '\0';
1399 if (strstr(recvbuf, "a1 OK") == NULL) {
1400 ERR("IMAP server login failed: %s", recvbuf);
1404 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1405 strncat(sendbuf, mail->folder,
1406 MAXDATASIZE - strlen(sendbuf) - 1);
1407 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1408 MAXDATASIZE - strlen(sendbuf) - 1);
1409 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1414 timeout.tv_sec = 60; // 60 second timeout i guess
1415 timeout.tv_usec = 0;
1417 FD_SET(sockfd, &fdset);
1418 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1421 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1428 recvbuf[numbytes] = '\0';
1429 if (strstr(recvbuf, "a2 OK") == NULL) {
1430 ERR("IMAP status failed: %s", recvbuf);
1434 // now we get the data
1435 reply = strstr(recvbuf, " (MESSAGES ");
1437 *strchr(reply, ')') = '\0';
1438 if (reply == NULL) {
1439 ERR("Error parsing IMAP response: %s", recvbuf);
1443 pthread_mutex_lock(&(mail->thread_info.mutex));
1444 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1447 pthread_mutex_unlock(&(mail->thread_info.mutex));
1449 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1450 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1455 timeout.tv_sec = 60; // 60 second timeout i guess
1456 timeout.tv_usec = 0;
1458 FD_SET(sockfd, &fdset);
1459 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1462 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1469 recvbuf[numbytes] = '\0';
1470 if (strstr(recvbuf, "a3 OK") == NULL) {
1471 ERR("IMAP logout failed: %s", recvbuf);
1476 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1477 if (system(mail->command) == -1) {
1482 old_unseen = mail->unseen;
1483 old_messages = mail->messages;
1484 mail->last_update = update_time;
1485 usleep(100); // prevent race condition
1486 if (get_time() - mail->last_update >
1490 unsigned int delay =
1491 1000000.0 * (mail->interval -
1493 mail->last_update));
1494 if (delay < update_interval * 500000) {
1495 delay = update_interval * 1000000;
1500 ERR("exiting imap thread");
1505 void *pop3_thread(struct mail_s *mail)
1506 { // pthreads are really beginning to piss me off
1508 int run_code = threads_runnable;
1509 update_time = get_time();
1510 int sockfd, numbytes;
1511 char recvbuf[MAXDATASIZE];
1512 char sendbuf[MAXDATASIZE];
1515 unsigned int old_unseen = UINT_MAX;
1517 struct sockaddr_in their_addr; // connector's address information
1518 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1519 herror("gethostbyname");
1522 while (threads_runnable == run_code && fail < 5) {
1524 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1525 sleep((int)mail->interval);
1527 update_time = get_time();
1528 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1534 their_addr.sin_family = AF_INET; // host byte order
1535 their_addr.sin_port = htons(mail->port); // short, network byte order
1536 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1537 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1540 (sockfd, (struct sockaddr *) &their_addr,
1541 sizeof(struct sockaddr)) == -1) {
1546 struct timeval timeout;
1549 timeout.tv_sec = 60; // 60 second timeout i guess
1550 timeout.tv_usec = 0;
1552 FD_SET(sockfd, &fdset);
1553 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1556 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1563 ERR("POP3 connection failed: timeout\n");
1567 recvbuf[numbytes] = '\0';
1568 if (strstr(recvbuf, "+OK ") != recvbuf) {
1569 ERR("POP3 connection failed, probably not a POP3 server");
1573 strncpy(sendbuf, "USER ", MAXDATASIZE);
1574 strncat(sendbuf, mail->user,
1575 MAXDATASIZE - strlen(sendbuf) - 1);
1576 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1577 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1578 perror("send USER");
1582 timeout.tv_sec = 60; // 60 second timeout i guess
1583 timeout.tv_usec = 0;
1585 FD_SET(sockfd, &fdset);
1586 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1589 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1591 perror("recv USER");
1596 recvbuf[numbytes] = '\0';
1597 if (strstr(recvbuf, "+OK ") == NULL) {
1598 ERR("POP3 server login failed: %s", recvbuf);
1602 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1603 strncat(sendbuf, mail->pass,
1604 MAXDATASIZE - strlen(sendbuf) - 1);
1605 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1606 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1607 perror("send PASS");
1611 timeout.tv_sec = 60; // 60 second timeout i guess
1612 timeout.tv_usec = 0;
1614 FD_SET(sockfd, &fdset);
1615 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1618 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1620 perror("recv PASS");
1625 recvbuf[numbytes] = '\0';
1626 if (strstr(recvbuf, "+OK ") == NULL) {
1627 ERR("POP3 server login failed: %s", recvbuf);
1631 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1632 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1633 perror("send STAT");
1637 timeout.tv_sec = 60; // 60 second timeout i guess
1638 timeout.tv_usec = 0;
1640 FD_SET(sockfd, &fdset);
1641 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1644 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1646 perror("recv STAT");
1651 recvbuf[numbytes] = '\0';
1652 if (strstr(recvbuf, "+OK ") == NULL) {
1653 ERR("POP3 status failed: %s", recvbuf);
1657 // now we get the data
1658 reply = recvbuf + 4;
1659 if (reply == NULL) {
1660 ERR("Error parsing POP3 response: %s", recvbuf);
1664 pthread_mutex_lock(&(mail->thread_info.mutex));
1665 sscanf(reply, "%lu %lu", &mail->unseen,
1668 pthread_mutex_unlock(&(mail->thread_info.mutex));
1670 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1671 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1672 perror("send QUIT");
1676 timeout.tv_sec = 60; // 60 second timeout i guess
1677 timeout.tv_usec = 0;
1679 FD_SET(sockfd, &fdset);
1680 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1683 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1685 perror("recv QUIT");
1690 recvbuf[numbytes] = '\0';
1691 if (strstr(recvbuf, "+OK") == NULL) {
1692 ERR("POP3 logout failed: %s", recvbuf);
1697 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1698 if (system(mail->command) == -1) {
1703 old_unseen = mail->unseen;
1704 mail->last_update = update_time;
1705 usleep(100); // prevent race condition
1706 if (get_time() - mail->last_update >
1710 unsigned int delay =
1711 1000000.0 * (mail->interval -
1713 mail->last_update));
1714 if (delay < update_interval * 500000) {
1715 delay = update_interval * 1000000;
1720 ERR("exiting pop3 thread");
1726 void *threaded_exec(struct text_object *obj) { // pthreads are really beginning to piss me off
1728 int run_code = threads_runnable;
1729 while (threads_runnable == run_code) {
1730 update_time = get_time();
1731 char *p2 = obj->data.execi.buffer;
1732 FILE *fp = popen(obj->data.execi.cmd,"r");
1733 pthread_mutex_lock(&(obj->data.execi.thread_info.mutex));
1734 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
1737 if (n2 && p2[n2 - 1] == '\n') {
1741 if (*p2 == '\001') {
1746 pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
1747 obj->data.execi.last_update = update_time;
1748 usleep(100); // prevent race condition
1749 if (get_time() - obj->data.execi.last_update > obj->data.execi.interval) {
1752 unsigned int delay = 1000000.0 * (obj->data.execi.interval -(get_time() - obj->data.execi.last_update));
1753 if (delay < update_interval * 500000) {
1754 delay = update_interval * 1000000;
1759 ERR("exiting thread");
1764 static struct text_object *new_text_object_internal()
1766 struct text_object *obj = malloc(sizeof(struct text_object));
1767 memset(obj, 0, sizeof(struct text_object));
1774 if (mlconfig.mldonkey_hostname) {
1775 free(mlconfig.mldonkey_hostname);
1776 mlconfig.mldonkey_hostname = NULL;
1781 static void free_text_objects(unsigned int count, struct text_object *objs)
1784 for (i = 0; i < count; i++) {
1785 switch (objs[i].type) {
1787 close(objs[i].data.i);
1790 close(objs[i].data.i);
1793 close(objs[i].data.i2c.fd);
1796 free(objs[i].data.s);
1799 free(objs[i].data.s);
1802 free(objs[i].data.tztime.tz);
1803 free(objs[i].data.tztime.fmt);
1808 case OBJ_imap_unseen:
1809 if (!objs[i].global_mode) {
1810 free(objs[i].data.mail);
1813 case OBJ_imap_messages:
1814 if (!objs[i].global_mode) {
1815 free(objs[i].data.mail);
1821 case OBJ_pop3_unseen:
1822 if (!objs[i].global_mode) {
1823 free(objs[i].data.mail);
1827 if (!objs[i].global_mode) {
1828 free(objs[i].data.mail);
1831 case OBJ_if_existing:
1832 case OBJ_if_mounted:
1833 case OBJ_if_running:
1834 free(objs[i].data.ifblock.s);
1837 free(objs[i].data.tail.logfile);
1838 free(objs[i].data.tail.buffer);
1840 case OBJ_text: case OBJ_font:
1841 free(objs[i].data.s);
1844 free(objs[i].data.s);
1847 free(objs[i].data.s);
1850 free(objs[i].data.s);
1853 free(objs[i].data.s);
1855 /* case OBJ_execibar:
1856 free(objs[i].data.s);
1858 case OBJ_execigraph:
1859 free(objs[i].data.s);
1862 case OBJ_iconv_start:
1868 if (info.mpd.title) {
1869 free(info.mpd.title);
1873 case OBJ_mpd_artist:
1874 if (info.mpd.artist) {
1875 free(info.mpd.artist);
1876 info.mpd.artist = 0;
1880 if (info.mpd.album) {
1881 free(info.mpd.album);
1885 case OBJ_mpd_random:
1886 if (info.mpd.random) {
1887 free(info.mpd.random);
1888 info.mpd.random = 0;
1891 case OBJ_mpd_repeat:
1892 if (info.mpd.repeat) {
1893 free(info.mpd.repeat);
1894 info.mpd.repeat = 0;
1898 if (info.mpd.track) {
1899 free(info.mpd.track);
1904 if (info.mpd.name) {
1905 free(info.mpd.name);
1910 if (info.mpd.file) {
1911 free(info.mpd.file);
1915 case OBJ_mpd_status:
1916 if (info.mpd.status) {
1917 free(info.mpd.status);
1918 info.mpd.status = 0;
1922 if (info.mpd.artist) {
1923 free(info.mpd.artist);
1924 info.mpd.artist = 0;
1926 if (info.mpd.title) {
1927 free(info.mpd.title);
1930 if (info.mpd.file) {
1931 free(info.mpd.file);
1938 case OBJ_xmms2_artist:
1939 if (info.xmms2.artist) {
1940 free(info.xmms2.artist);
1941 info.xmms2.artist = 0;
1944 case OBJ_xmms2_album:
1945 if (info.xmms2.album) {
1946 free(info.xmms2.album);
1947 info.xmms2.album = 0;
1950 case OBJ_xmms2_title:
1951 if (info.xmms2.title) {
1952 free(info.xmms2.title);
1953 info.xmms2.title = 0;
1956 case OBJ_xmms2_genre:
1957 if (info.xmms2.genre) {
1958 free(info.xmms2.genre);
1959 info.xmms2.genre = 0;
1962 case OBJ_xmms2_comment:
1963 if (info.xmms2.comment) {
1964 free(info.xmms2.comment);
1965 info.xmms2.comment = 0;
1968 case OBJ_xmms2_decoder:
1969 if (info.xmms2.decoder) {
1970 free(info.xmms2.decoder);
1974 case OBJ_xmms2_transport:
1975 if (info.xmms2.transport) {
1976 free(info.xmms2.transport);
1981 if (info.xmms2.url) {
1982 free(info.xmms2.url);
1986 case OBJ_xmms2_date:
1987 if (info.xmms2.date) {
1988 free(info.xmms2.date);
1989 info.xmms2.date = 0;
1992 case OBJ_xmms2_status:
1993 if (info.xmms2.status) {
1994 free(info.xmms2.status);
1995 info.xmms2.status = 0;
1998 case OBJ_xmms2_smart:
1999 if (info.xmms2.artist) {
2000 free(info.xmms2.artist);
2001 info.xmms2.artist = 0;
2003 if (info.xmms2.title) {
2004 free(info.xmms2.title);
2005 info.xmms2.title = 0;
2007 if (info.xmms2.url) {
2008 free(info.xmms2.url);
2014 case OBJ_bmpx_title:
2015 case OBJ_bmpx_artist:
2016 case OBJ_bmpx_album:
2017 case OBJ_bmpx_track:
2019 case OBJ_bmpx_bitrate:
2023 free(objs[i].data.s);
2027 free(objs[i].data.execi.cmd);
2028 free(objs[i].data.execi.buffer);
2031 free(objs[i].data.execi.cmd);
2032 free(objs[i].data.execi.buffer);
2035 if (info.first_process) {
2036 free_all_processes();
2037 info.first_process = NULL;
2041 if (info.first_process) {
2042 free_all_processes();
2043 info.first_process = NULL;
2048 free(objs[i].data.hddtemp.dev);
2049 free(objs[i].data.hddtemp.addr);
2055 //text_objects = NULL;
2056 //text_object_count = 0;
2059 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2064 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2065 *a = mixer_init(buf1);
2066 (void) scan_bar(arg + n, w, h);
2069 (void) scan_bar(arg, w, h);
2074 /* construct_text_object() creates a new text_object */
2075 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2077 //struct text_object *obj = new_text_object();
2078 struct text_object *obj = new_text_object_internal();
2081 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2082 #define END ; } } else
2086 obj->type = OBJ_color;
2087 obj->data.l = get_x11_color(s);
2090 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2091 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2092 END OBJ(acpiacadapter, 0)
2093 #if defined(__linux__)
2100 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2102 obj->data.cpu_index=1;
2103 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2107 obj->data.cpu_index=atoi(&arg[0]);
2116 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2118 obj->data.cpu_index=1;
2119 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2123 obj->data.cpu_index=atoi(&arg[0]);
2126 END OBJ(voltage_mv, 0)
2132 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2134 obj->data.cpu_index=1;
2135 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2139 obj->data.cpu_index=atoi(&arg[0]);
2142 END OBJ(voltage_v, 0)
2148 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2150 obj->data.cpu_index=1;
2151 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2155 obj->data.cpu_index=atoi(&arg[0]);
2161 #endif /* __linux__ */
2162 END OBJ(freq_dyn, 0);
2163 END OBJ(freq_dyn_g, 0);
2164 END OBJ(acpifan, 0);
2165 END OBJ(battery, 0);
2168 sscanf(arg, "%63s", bat);
2170 strcpy(bat, "BAT0");
2171 obj->data.s = strdup(bat);
2172 #if defined(__linux__)
2173 END OBJ(i8k_version, INFO_I8K)
2174 END OBJ(i8k_bios, INFO_I8K)
2175 END OBJ(i8k_serial, INFO_I8K)
2176 END OBJ(i8k_cpu_temp, INFO_I8K)
2177 END OBJ(i8k_cpu_tempf, INFO_I8K)
2178 END OBJ(i8k_left_fan_status, INFO_I8K)
2179 END OBJ(i8k_right_fan_status, INFO_I8K)
2180 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2181 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2182 END OBJ(i8k_ac_status, INFO_I8K)
2183 END OBJ(i8k_buttons_status, INFO_I8K)
2185 END OBJ(ibm_temps, 0)
2186 if (!isdigit(arg[0])
2188 || atoi(&arg[0]) >=8)
2191 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2193 obj->data.sensor = atoi(&arg[0]);
2194 END OBJ(ibm_volume, 0)
2195 END OBJ(ibm_brightness, 0)
2196 END OBJ(pb_battery, 0)
2197 if (arg && strcmp(arg, "status") == 0) {
2198 obj->data.i = PB_BATT_STATUS;
2199 } else if (arg && strcmp(arg, "percent") == 0) {
2200 obj->data.i = PB_BATT_PERCENT;
2201 } else if (arg && strcmp(arg, "time") == 0) {
2202 obj->data.i = PB_BATT_TIME;
2204 ERR("pb_battery: needs one argument: status, percent or time");
2209 #endif /* __linux__ */
2210 END OBJ(buffers, INFO_BUFFERS)
2211 END OBJ(cached, INFO_BUFFERS)
2212 END OBJ(cpu, INFO_CPU)
2214 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2215 obj->data.cpu_index = atoi(&arg[3]);
2217 } else {obj->data.cpu_index = 0; }
2219 obj->data.cpu_index = 0;
2221 END OBJ(cpubar, INFO_CPU)
2223 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2224 obj->data.cpu_index = atoi(&arg[3]);
2227 else {obj->data.cpu_index = 0;}
2228 (void) scan_bar(arg, &obj->a, &obj->b);
2230 (void) scan_bar(arg, &obj->a, &obj->b);
2231 obj->data.cpu_index = 0;
2233 END OBJ(cpugraph, INFO_CPU)
2235 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2236 obj->data.cpu_index = atoi(&arg[3]);
2239 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2241 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2242 obj->data.cpu_index = 0;
2244 END OBJ(diskio, INFO_DISKIO)
2245 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2248 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2252 obj->data.s = scan_font(arg);
2254 OBJ(downspeed, INFO_NET)
2256 obj->data.net = get_net_stat(arg);
2259 CRIT_ERR("downspeed needs argument");
2261 END OBJ(downspeedf, INFO_NET)
2263 obj->data.net = get_net_stat(arg);
2266 CRIT_ERR("downspeedf needs argument");
2268 END OBJ(downspeedgraph, INFO_NET)
2269 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2271 sscanf(arg, "%63s %*i,%*i %*i", buf);
2272 obj->data.net = get_net_stat(buf);
2273 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2274 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2281 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2282 blockstart[blockdepth - 1] = object_count;
2283 obj->data.ifblock.pos = object_count + 2;
2285 ERR("$else: no matching $if_*");
2290 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2292 ERR("$endif: no matching $if_*");
2295 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2298 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2299 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2300 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2301 END OBJ(execibar, 0) unsigned int n;
2302 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2304 ERR("${execibar <interval> command}");
2305 obj->type = OBJ_text;
2306 snprintf(buf, 256, "${%s}", s);
2307 obj->data.s = strdup(buf);
2309 obj->data.execi.cmd = strdup(arg + n);
2311 END OBJ(execigraph, 0) unsigned int n;
2312 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2314 ERR("${execigraph <interval> command}");
2315 obj->type = OBJ_text;
2316 snprintf(buf, 256, "${%s}", s);
2317 obj->data.s = strdup(buf);
2319 obj->data.execi.cmd = strdup(arg + n);
2321 END OBJ(execi, 0) unsigned int n;
2324 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2326 ERR("${execi <interval> command}");
2327 obj->type = OBJ_text;
2328 snprintf(buf, 256, "${%s}", s);
2329 obj->data.s = strdup(buf);
2331 obj->data.execi.cmd = strdup(arg + n);
2332 obj->data.execi.buffer =
2333 (char *) calloc(1, TEXT_BUFFER_SIZE);
2335 END OBJ(texeci, 0) unsigned int n;
2337 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2339 ERR("${texeci <interval> command}");
2340 obj->type = OBJ_text;
2341 snprintf(buf, 256, "${%s}", s);
2342 obj->data.s = strdup(buf);
2344 obj->data.execi.cmd = strdup(arg + n);
2345 obj->data.execi.buffer =
2346 (char *) calloc(1, TEXT_BUFFER_SIZE);
2348 obj->data.execi.pos = -1;
2349 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2351 FILE *fp = popen(arg, "r");
2355 n = fread(buf, 1, 2048, fp);
2358 if (n && buf[n - 1] == '\n')
2363 obj->data.s = strdup(buf);
2365 obj->data.s = strdup("");
2368 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2369 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2371 while (isspace(*arg))
2377 obj->data.fsbar.fs = prepare_fs_stat(arg);
2378 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2381 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2385 obj->data.fsbar.fs = prepare_fs_stat(arg);
2386 END OBJ(fs_free, INFO_FS) if (!arg)
2388 obj->data.fs = prepare_fs_stat(arg);
2389 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2391 obj->data.fs = prepare_fs_stat(arg);
2392 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2394 obj->data.fs = prepare_fs_stat(arg);
2395 END OBJ(fs_size, INFO_FS) if (!arg)
2397 obj->data.fs = prepare_fs_stat(arg);
2398 END OBJ(fs_used, INFO_FS) if (!arg)
2400 obj->data.fs = prepare_fs_stat(arg);
2401 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2402 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2403 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2407 ERR("goto needs arguments");
2408 obj->type = OBJ_text;
2409 obj->data.s = strdup("${goto}");
2413 obj->data.i = atoi(arg);
2418 if (sscanf(arg, "%d %d", &a, &b) != 2)
2419 sscanf(arg, "%d", &b);
2423 obj->data.pair.a = a;
2424 obj->data.pair.b = b;
2426 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2430 ERR("i2c needs arguments");
2431 obj->type = OBJ_text;
2432 //obj->data.s = strdup("${i2c}");
2436 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2437 /* if scanf couldn't read three values, read type and num and use
2439 sscanf(arg, "%63s %d", buf2, &n);
2441 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2442 obj->data.i2c.devtype);
2443 strncpy(obj->data.i2c.type, buf2, 63);
2446 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2447 obj->data.i2c.devtype);
2448 strncpy(obj->data.i2c.type, buf2, 63);
2451 END OBJ(top, INFO_TOP)
2455 ERR("top needs arguments");
2456 obj->type = OBJ_text;
2457 //obj->data.s = strdup("${top}");
2460 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2461 if (strcmp(buf, "name") == 0) {
2462 obj->data.top.type = TOP_NAME;
2463 } else if (strcmp(buf, "cpu") == 0) {
2464 obj->data.top.type = TOP_CPU;
2465 } else if (strcmp(buf, "pid") == 0) {
2466 obj->data.top.type = TOP_PID;
2467 } else if (strcmp(buf, "mem") == 0) {
2468 obj->data.top.type = TOP_MEM;
2470 ERR("invalid arg for top");
2473 if (n < 1 || n > 10) {
2474 CRIT_ERR("invalid arg for top");
2477 obj->data.top.num = n - 1;
2481 ERR("invalid args given for top");
2484 END OBJ(top_mem, INFO_TOP)
2488 ERR("top_mem needs arguments");
2489 obj->type = OBJ_text;
2490 obj->data.s = strdup("${top_mem}");
2493 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2494 if (strcmp(buf, "name") == 0) {
2495 obj->data.top.type = TOP_NAME;
2496 } else if (strcmp(buf, "cpu") == 0) {
2497 obj->data.top.type = TOP_CPU;
2498 } else if (strcmp(buf, "pid") == 0) {
2499 obj->data.top.type = TOP_PID;
2500 } else if (strcmp(buf, "mem") == 0) {
2501 obj->data.top.type = TOP_MEM;
2503 ERR("invalid arg for top");
2506 if (n < 1 || n > 10) {
2507 CRIT_ERR("invalid arg for top");
2510 obj->data.top.num = n - 1;
2514 ERR("invalid args given for top");
2517 END OBJ(addr, INFO_NET)
2519 obj->data.net = get_net_stat(arg);
2522 CRIT_ERR("addr needs argument");
2524 END OBJ(linkstatus, INFO_WIFI)
2526 obj->data.net = get_net_stat(arg);
2529 CRIT_ERR("linkstatus needs argument");
2535 ERR("tail needs arguments");
2536 obj->type = OBJ_text;
2537 obj->data.s = strdup("${tail}");
2540 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2541 if (n1 < 1 || n1 > 30) {
2542 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2546 fp = fopen(buf, "r");
2548 obj->data.tail.logfile =
2549 malloc(TEXT_BUFFER_SIZE);
2550 strcpy(obj->data.tail.logfile, buf);
2551 obj->data.tail.wantedlines = n1 - 1;
2552 obj->data.tail.interval =
2553 update_interval * 2;
2557 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2560 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2561 if (n1 < 1 || n1 > 30) {
2563 ("invalid arg for tail, number of lines must be between 1 and 30");
2565 } else if (n2 < 1 || n2 < update_interval) {
2567 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2571 fp = fopen(buf, "r");
2573 obj->data.tail.logfile =
2574 malloc(TEXT_BUFFER_SIZE);
2575 strcpy(obj->data.tail.logfile, buf);
2576 obj->data.tail.wantedlines = n1 - 1;
2577 obj->data.tail.interval = n2;
2581 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2587 ERR("invalid args given for tail");
2590 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
2595 ERR("head needs arguments");
2596 obj->type = OBJ_text;
2597 obj->data.s = strdup("${head}");
2600 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2601 if (n1 < 1 || n1 > 30) {
2602 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2606 fp = fopen(buf, "r");
2608 obj->data.tail.logfile =
2609 malloc(TEXT_BUFFER_SIZE);
2610 strcpy(obj->data.tail.logfile, buf);
2611 obj->data.tail.wantedlines = n1 - 1;
2612 obj->data.tail.interval =
2613 update_interval * 2;
2617 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2620 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2621 if (n1 < 1 || n1 > 30) {
2623 ("invalid arg for head, number of lines must be between 1 and 30");
2625 } else if (n2 < 1 || n2 < update_interval) {
2627 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2631 fp = fopen(buf, "r");
2633 obj->data.tail.logfile =
2634 malloc(TEXT_BUFFER_SIZE);
2635 strcpy(obj->data.tail.logfile, buf);
2636 obj->data.tail.wantedlines = n1 - 1;
2637 obj->data.tail.interval = n2;
2641 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2647 ERR("invalid args given for head");
2650 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
2651 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2653 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2654 if (r >= 3 && (c < 1 || c > 3))
2656 if (r >= 2 && (b < 1 || b > 3))
2658 if (r >= 1 && (a < 1 || a > 3))
2661 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2662 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2663 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2664 END OBJ(if_existing, 0)
2665 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2666 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2669 ERR("if_existing needs an argument");
2670 obj->data.ifblock.s = 0;
2672 obj->data.ifblock.s = strdup(arg);
2673 blockstart[blockdepth] = object_count;
2674 obj->data.ifblock.pos = object_count + 2;
2676 END OBJ(if_mounted, 0)
2677 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2678 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2681 ERR("if_mounted needs an argument");
2682 obj->data.ifblock.s = 0;
2684 obj->data.ifblock.s = strdup(arg);
2685 blockstart[blockdepth] = object_count;
2686 obj->data.ifblock.pos = object_count + 2;
2688 END OBJ(if_running, 0)
2689 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2690 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2694 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2695 obj->data.ifblock.s = strdup(buf);
2697 ERR("if_running needs an argument");
2698 obj->data.ifblock.s = 0;
2700 blockstart[blockdepth] = object_count;
2701 obj->data.ifblock.pos = object_count + 2;
2705 END OBJ(mails, INFO_MAIL)
2706 END OBJ(mem, INFO_MEM)
2707 END OBJ(memmax, INFO_MEM)
2708 END OBJ(memperc, INFO_MEM)
2709 END OBJ(membar, INFO_MEM)
2710 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2711 END OBJ(memgraph, INFO_MEM)
2712 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2713 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2714 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2715 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2716 END OBJ(mixerbar, INFO_MIXER)
2717 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2718 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2719 END OBJ(mixerlbar, INFO_MIXER)
2720 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2721 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2722 END OBJ(mixerrbar, INFO_MIXER)
2723 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2724 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2727 OBJ(ml_upload_counter, INFO_MLDONKEY)
2728 END OBJ(ml_download_counter, INFO_MLDONKEY)
2729 END OBJ(ml_nshared_files, INFO_MLDONKEY)
2730 END OBJ(ml_shared_counter, INFO_MLDONKEY)
2731 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
2732 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
2733 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
2734 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
2735 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
2736 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
2738 OBJ(new_mails, INFO_MAIL)
2739 END OBJ(nodename, 0)
2740 END OBJ(processes, INFO_PROCS)
2741 END OBJ(running_processes, INFO_RUN_PROCS)
2742 END OBJ(shadecolor, 0)
2744 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2746 END OBJ(outlinecolor, 0)
2748 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2750 END OBJ(stippled_hr, 0)
2752 int a = stippled_borders, b = 1;
2754 if (sscanf(arg, "%d %d", &a, &b) != 2)
2755 sscanf(arg, "%d", &b);
2759 obj->data.pair.a = a;
2760 obj->data.pair.b = b;
2762 END OBJ(swap, INFO_MEM)
2763 END OBJ(swapmax, INFO_MEM)
2764 END OBJ(swapperc, INFO_MEM)
2765 END OBJ(swapbar, INFO_MEM)
2766 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2767 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2769 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2770 obj->data.i2c.devtype);
2771 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2773 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2774 obj->data.i2c.devtype);
2775 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2776 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2778 char buf1[256], buf2[256], *fmt, *tz;
2781 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2790 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2791 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2793 END OBJ(iconv_start, 0)
2794 if (iconv_converting) {
2795 CRIT_ERR("You must stop your last iconv conversion before starting another");
2798 char iconv_from[CODEPAGE_LENGTH];
2799 char iconv_to[CODEPAGE_LENGTH];
2800 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2801 CRIT_ERR("Invalid arguments for iconv_start");
2804 new_iconv = iconv_open(iconv_to, iconv_from);
2805 if (new_iconv == (iconv_t)(-1)) {
2806 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2808 obj->a = register_iconv(&new_iconv);
2809 iconv_converting = 1;
2813 CRIT_ERR("Iconv requires arguments");
2815 END OBJ(iconv_stop, 0)
2816 iconv_converting = 0;
2819 END OBJ(totaldown, INFO_NET)
2821 obj->data.net = get_net_stat(arg);
2824 CRIT_ERR("totaldown needs argument");
2826 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2828 obj->data.net = get_net_stat(arg);
2831 CRIT_ERR("totalup needs argument");
2834 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2835 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2836 END OBJ(upspeed, INFO_NET)
2838 obj->data.net = get_net_stat(arg);
2841 CRIT_ERR("upspeed needs argument");
2843 END OBJ(upspeedf, INFO_NET)
2845 obj->data.net = get_net_stat(arg);
2848 CRIT_ERR("upspeedf needs argument");
2851 END OBJ(upspeedgraph, INFO_NET)
2852 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2854 sscanf(arg, "%63s %*i,%*i %*i", buf);
2855 obj->data.net = get_net_stat(buf);
2856 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2857 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2862 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2863 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2864 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2865 OBJ(apm_adapter, 0) END
2866 OBJ(apm_battery_life, 0) END
2867 OBJ(apm_battery_time, 0) END
2868 #endif /* __FreeBSD__ */
2870 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
2871 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2872 END OBJ(seti_credit, INFO_SETI) END
2877 obj->data.mail = parse_mail_args(IMAP, arg);
2878 obj->global_mode = 0;
2880 obj->global_mode = 1;
2883 OBJ(imap_messages, 0)
2886 obj->data.mail = parse_mail_args(IMAP, arg);
2887 obj->global_mode = 0;
2889 obj->global_mode = 1;
2895 obj->data.mail = parse_mail_args(POP3, arg);
2896 obj->global_mode = 0;
2898 obj->global_mode = 1;
2904 obj->data.mail = parse_mail_args(POP3, arg);
2905 obj->global_mode = 0;
2907 obj->global_mode = 1;
2911 OBJ(mpd_artist, INFO_MPD)
2912 END OBJ(mpd_title, INFO_MPD)
2913 END OBJ(mpd_random, INFO_MPD)
2914 END OBJ(mpd_repeat, INFO_MPD)
2915 END OBJ(mpd_elapsed, INFO_MPD)
2916 END OBJ(mpd_length, INFO_MPD)
2917 END OBJ(mpd_track, INFO_MPD)
2918 END OBJ(mpd_name, INFO_MPD)
2919 END OBJ(mpd_file, INFO_MPD)
2920 END OBJ(mpd_percent, INFO_MPD)
2921 END OBJ(mpd_album, INFO_MPD)
2922 END OBJ(mpd_vol, INFO_MPD)
2923 END OBJ(mpd_bitrate, INFO_MPD)
2924 END OBJ(mpd_status, INFO_MPD)
2925 END OBJ(mpd_bar, INFO_MPD)
2926 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2927 END OBJ(mpd_smart, INFO_MPD) END
2930 OBJ(xmms2_artist, INFO_XMMS2)
2931 END OBJ(xmms2_album, INFO_XMMS2)
2932 END OBJ(xmms2_title, INFO_XMMS2)
2933 END OBJ(xmms2_genre, INFO_XMMS2)
2934 END OBJ(xmms2_comment, INFO_XMMS2)
2935 END OBJ(xmms2_decoder, INFO_XMMS2)
2936 END OBJ(xmms2_transport, INFO_XMMS2)
2937 END OBJ(xmms2_url, INFO_XMMS2)
2938 END OBJ(xmms2_tracknr, INFO_XMMS2)
2939 END OBJ(xmms2_bitrate, INFO_XMMS2)
2940 END OBJ(xmms2_date, INFO_XMMS2)
2941 END OBJ(xmms2_id, INFO_XMMS2)
2942 END OBJ(xmms2_duration, INFO_XMMS2)
2943 END OBJ(xmms2_elapsed, INFO_XMMS2)
2944 END OBJ(xmms2_size, INFO_XMMS2)
2945 END OBJ(xmms2_status, INFO_XMMS2)
2946 END OBJ(xmms2_percent, INFO_XMMS2)
2947 END OBJ(xmms2_bar, INFO_XMMS2)
2948 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2949 END OBJ(xmms2_smart, INFO_XMMS2)
2952 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2953 OBJ(xmms_status, INFO_XMMS) END
2954 OBJ(xmms_title, INFO_XMMS) END
2955 OBJ(xmms_length, INFO_XMMS) END
2956 OBJ(xmms_length_seconds, INFO_XMMS) END
2957 OBJ(xmms_position, INFO_XMMS) END
2958 OBJ(xmms_position_seconds, INFO_XMMS) END
2959 OBJ(xmms_bitrate, INFO_XMMS) END
2960 OBJ(xmms_frequency, INFO_XMMS) END
2961 OBJ(xmms_channels, INFO_XMMS) END
2962 OBJ(xmms_filename, INFO_XMMS) END
2963 OBJ(xmms_playlist_length, INFO_XMMS) END
2964 OBJ(xmms_playlist_position, INFO_XMMS) END
2965 OBJ(xmms_bar, INFO_XMMS)
2966 (void) scan_bar(arg, &obj->a, &obj->b);
2970 OBJ(bmpx_title, INFO_BMPX)
2971 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2973 OBJ(bmpx_artist, INFO_BMPX)
2974 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2976 OBJ(bmpx_album, INFO_BMPX)
2977 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2979 OBJ(bmpx_track, INFO_BMPX)
2980 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2982 OBJ(bmpx_uri, INFO_BMPX)
2983 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2985 OBJ(bmpx_bitrate, INFO_BMPX)
2986 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2991 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
2992 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2993 ERR("hddtemp needs arguments");
2994 obj->type = OBJ_text;
2995 obj->data.s = strdup("${hddtemp}");
3000 #ifdef TCP_PORT_MONITOR
3001 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3002 int argc, port_begin, port_end, item, connection_index;
3004 memset(itembuf,0,sizeof(itembuf));
3006 /* massive argument checking */
3008 CRIT_ERR("tcp_portmon: needs arguments");
3010 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3011 if ( (argc != 3) && (argc != 4) )
3013 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3015 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3017 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3019 if ( port_begin > port_end )
3021 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3023 if ( strncmp(itembuf,"count",31) == 0 )
3025 else if ( strncmp(itembuf,"rip",31) == 0 )
3027 else if ( strncmp(itembuf,"rhost",31) == 0 )
3029 else if ( strncmp(itembuf,"rport",31) == 0 )
3031 else if ( strncmp(itembuf,"rservice",31) == 0 )
3033 else if ( strncmp(itembuf,"lip",31) == 0 )
3035 else if ( strncmp(itembuf,"lhost",31) == 0 )
3037 else if ( strncmp(itembuf,"lport",31) == 0 )
3039 else if ( strncmp(itembuf,"lservice",31) == 0 )
3043 CRIT_ERR("tcp_portmon: invalid item specified");
3045 if ( (argc==3) && (item!=COUNT) )
3047 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3049 if ( (argc==4) && (connection_index<0) )
3051 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3053 /* ok, args looks good. save the text object data */
3054 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3055 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3056 obj->data.tcp_port_monitor.item = item;
3057 obj->data.tcp_port_monitor.connection_index = connection_index;
3059 /* if the port monitor collection hasn't been created, we must create it */
3060 if ( !info.p_tcp_port_monitor_collection )
3062 info.p_tcp_port_monitor_collection =
3063 create_tcp_port_monitor_collection( &tcp_port_monitor_collection_args );
3064 if ( !info.p_tcp_port_monitor_collection )
3066 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3070 /* if a port monitor for this port does not exist, create one and add it to the collection */
3071 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3073 tcp_port_monitor_t * p_monitor =
3074 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3077 CRIT_ERR("tcp_portmon: unable to create port monitor");
3079 /* add the newly created monitor to the collection */
3080 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3083 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3090 ERR("unknown variable %s", s);
3091 obj->type = OBJ_text;
3092 snprintf(buf, 256, "${%s}", s);
3093 obj->data.s = strdup(buf);
3100 static struct text_object *create_plain_text(const char *s)
3102 struct text_object *obj;
3104 if (s == NULL || *s == '\0') {
3108 obj = new_text_object_internal();
3110 obj->type = OBJ_text;
3111 obj->data.s = strdup(s);
3115 static struct text_object_list *extract_variable_text_internal(const char *p)
3117 struct text_object_list *retval;
3118 struct text_object *obj;
3121 retval = malloc(sizeof(struct text_object_list));
3122 memset(retval, 0, sizeof(struct text_object_list));
3123 retval->text_object_count = 0;
3125 long line = text_lines;
3133 obj = create_plain_text(s);
3135 // allocate memory for the object
3136 retval->text_objects = realloc(retval->text_objects,
3137 sizeof(struct text_object) * (retval->text_object_count+1));
3138 // assign the new object to the end of the list.
3139 memcpy(&retval->text_objects[retval->text_object_count++],
3140 obj, sizeof(struct text_object));
3152 /* variable is either $foo or ${foo} */
3156 while (*p && *p != '}')
3162 while (*p && (isalnum((int) *p)
3167 /* copy variable to buffer */
3168 len = (p - s > 255) ? 255 : (p - s);
3169 strncpy(buf, s, len);
3178 /* if variable wasn't found from environment, use some special */
3184 if (strchr(buf, ' ')) {
3185 arg = strchr(buf, ' ');
3188 while (isspace((int) *arg))
3194 /* lowercase variable name */
3201 // create new object
3202 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3204 // allocate memory for the object
3205 retval->text_objects = realloc(retval->text_objects,
3206 sizeof(struct text_object) * (retval->text_object_count+1));
3207 // assign the new object to the end of the list.
3208 memcpy(&retval->text_objects[retval->text_object_count++],
3209 obj, sizeof(struct text_object));
3215 obj = create_plain_text("$");
3217 // allocate memory for the object
3218 retval->text_objects = realloc(retval->text_objects,
3219 sizeof(struct text_object) * (retval->text_object_count+1));
3220 // assign the new object to the end of the list.
3221 memcpy(&retval->text_objects[retval->text_object_count++],
3222 obj, sizeof(struct text_object));
3229 obj = create_plain_text(s);
3231 // allocate memory for the object
3232 retval->text_objects = realloc(retval->text_objects,
3233 sizeof(struct text_object) * (retval->text_object_count+1));
3234 // assign the new object to the end of the list.
3235 memcpy(&retval->text_objects[retval->text_object_count++],
3236 obj, sizeof(struct text_object));
3241 ERR("one or more $endif's are missing");
3247 static void extract_variable_text(const char *p)
3249 struct text_object_list *list;
3251 free_text_objects(text_object_count, text_objects);
3252 text_object_count = 0;
3253 text_objects = NULL;
3257 #endif /* MLDONKEY */
3260 list = extract_variable_text_internal(p);
3261 text_objects = list->text_objects;
3262 text_object_count = list->text_object_count;
3269 void parse_conky_vars(char * text, char * p, struct information *cur) {
3270 struct text_object_list *object_list = extract_variable_text_internal(text);
3271 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3275 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3280 char buff_in[P_MAX_SIZE] = {0};
3281 iconv_converting = 0;
3284 for (i = 0; i < object_count; i++) {
3285 struct text_object *obj = &objs[i];
3287 #define OBJ(a) break; case OBJ_##a:
3289 switch (obj->type) {
3292 ERR("not implemented obj type %d",
3296 /* does anyone have decimals in acpi temperature? */
3298 snprintf(p, p_max_size, "%d", (int)
3299 get_acpi_temperature(obj->
3303 snprintf(p, 5, "%d ", (int)
3304 get_acpi_temperature(obj->
3309 /* does anyone have decimals in acpi temperature? */
3311 snprintf(p, p_max_size, "%d", (int)
3312 ((get_acpi_temperature(obj->
3314 i)+ 40) * 9.0 / 5 - 40));
3316 snprintf(p, 5, "%d ", (int)
3317 ((get_acpi_temperature(obj->
3319 i)+ 40) * 9.0 / 5 - 40));
3323 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index); /* pk */
3328 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index); /* pk */
3331 #if defined(__linux__)
3334 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3339 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3342 #endif /* __linux__ */
3346 get_freq_dynamic(p, 6, "%.0f ", 1 ); /* pk */
3348 get_freq_dynamic(p, p_max_size, "%.0f", 1 ); /* pk */
3353 get_freq_dynamic(p, 6, "%'.2f ", 1000); /* pk */
3355 get_freq_dynamic(p, p_max_size, "%'.2f", 1000); /* pk */
3359 get_adt746x_cpu(p, p_max_size); /* pk */
3362 get_adt746x_fan(p, p_max_size); /* pk */
3365 get_acpi_fan(p, p_max_size); /* pk */
3367 OBJ(acpiacadapter) {
3368 get_acpi_ac_adapter(p, p_max_size); /* pk */
3371 get_battery_stuff(p, p_max_size, obj->data.s);
3374 human_readable(cur->buffers * 1024, p, 255);
3377 human_readable(cur->cached * 1024, p, 255);
3380 if (obj->data.cpu_index > info.cpu_count) {
3381 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3382 CRIT_ERR("attempting to use more CPUs then you have!");
3385 snprintf(p, p_max_size, "%*d", pad_percents,
3386 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3389 snprintf(p, 4, "%*d ",
3391 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3397 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3400 new_graph(p, obj->a,
3401 obj->b, obj->c, obj->d,
3402 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3406 new_fg(p, obj->data.l);
3408 #if defined(__linux__)
3410 snprintf(p, p_max_size, "%s", i8k.version);
3413 snprintf(p, p_max_size, "%s", i8k.bios);
3416 snprintf(p, p_max_size, "%s", i8k.serial);
3419 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3421 OBJ(i8k_cpu_tempf) {
3423 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3424 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3426 OBJ(i8k_left_fan_status) {
3427 int left_fan_status;
3428 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3429 if(left_fan_status == 0) {
3430 snprintf(p, p_max_size,"off");
3431 } if(left_fan_status == 1) {
3432 snprintf(p, p_max_size, "low");
3433 } if(left_fan_status == 2) {
3434 snprintf(p, p_max_size, "high");
3438 OBJ(i8k_right_fan_status) {
3439 int right_fan_status;
3440 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3441 if(right_fan_status == 0) {
3442 snprintf(p, p_max_size,"off");
3443 } if(right_fan_status == 1) {
3444 snprintf(p, p_max_size, "low");
3445 } if(right_fan_status == 2) {
3446 snprintf(p, p_max_size, "high");
3449 OBJ(i8k_left_fan_rpm) {
3450 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3452 OBJ(i8k_right_fan_rpm) {
3453 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3455 OBJ(i8k_ac_status) {
3457 sscanf(i8k.ac_status, "%d", &ac_status);
3458 if(ac_status == -1) {
3459 snprintf(p, p_max_size,"disabled (read i8k docs)");
3460 } if(ac_status == 0) {
3461 snprintf(p, p_max_size, "off");
3462 } if(ac_status == 1) {
3463 snprintf(p, p_max_size, "on");
3466 OBJ(i8k_buttons_status) {
3467 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3471 get_ibm_acpi_fan(p, p_max_size);
3474 get_ibm_acpi_temps();
3475 snprintf(p, p_max_size, "%d",
3476 ibm_acpi.temps[obj->data.sensor]);
3479 get_ibm_acpi_volume(p, p_max_size);
3481 OBJ(ibm_brightness) {
3482 get_ibm_acpi_brightness(p, p_max_size);
3485 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3487 #endif /* __linux__ */
3491 new_font(p, obj->data.s);
3496 if (diskio_value > 1024*1024) {
3497 snprintf(p, p_max_size, "%.1fGiB",
3498 (double)diskio_value/1024/1024);
3499 } else if (diskio_value > 1024) {
3500 snprintf(p, p_max_size, "%.1fMiB",
3501 (double)diskio_value/1024);
3502 } else if (diskio_value > 0) {
3503 snprintf(p, p_max_size, "%dKiB", diskio_value);
3505 snprintf(p, p_max_size, "%dB", diskio_value);
3508 if (diskio_value > 1024*1024) {
3509 snprintf(p, 6, "%.1fGiB ",
3510 (double)diskio_value/1024/1024);
3511 } else if (diskio_value > 1024) {
3512 snprintf(p, 6, "%.1fMiB ",
3513 (double)diskio_value/1024);
3514 } else if (diskio_value > 0) {
3515 snprintf(p, 6, "%dKiB ", diskio_value);
3517 snprintf(p, 6, "%dB ", diskio_value);
3522 new_graph(p, obj->a,
3523 obj->b, obj->c, obj->d,
3524 diskio_value, obj->e, 1);
3529 snprintf(p, p_max_size, "%d",
3530 (int) (obj->data.net->
3534 snprintf(p, 6, "%d ",
3535 (int) (obj->data.net->
3541 snprintf(p, p_max_size, "%.1f",
3543 recv_speed / 1024.0);
3545 snprintf(p, 8, "%.1f ",
3547 recv_speed / 1024.0);
3549 OBJ(downspeedgraph) {
3550 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
3551 obj->data.net->recv_speed = 0.01;
3552 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3553 (obj->data.net->recv_speed /
3554 1024.0), obj->e, 1);
3558 i = obj->data.ifblock.pos - 1;
3568 snprintf(p, p_max_size, "%u.%u.%u.%u",
3569 obj->data.net->addr.
3571 obj->data.net->addr.
3573 obj->data.net->addr.
3575 obj->data.net->addr.
3580 snprintf(p, p_max_size, "%d",
3581 obj->data.net->linkstatus);
3583 #if defined(IMLIB2) && defined(X11)
3588 Imlib_Image image, buffer;
3589 image = imlib_load_image(obj->data.s);
3590 imlib_context_set_image(image);
3593 w = imlib_image_get_width();
3594 h = imlib_image_get_height();
3595 buffer = imlib_create_image(w, h);
3596 imlib_context_set_display(display);
3597 imlib_context_set_drawable(window.drawable);
3598 imlib_context_set_colormap(DefaultColormap(display, screen));
3599 imlib_context_set_visual(DefaultVisual(display, screen));
3600 imlib_context_set_image(buffer);
3601 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3602 imlib_render_image_on_drawable(text_start_x, text_start_y);
3604 imlib_context_set_image(image);
3611 FILE *fp = popen(obj->data.s, "r");
3612 int length = fread(p, 1, p_max_size, fp);
3615 /*output[length] = '\0';
3616 if (length > 0 && output[length - 1] == '\n') {
3617 output[length - 1] = '\0';
3620 if (length > 0 && p[length - 1] == '\n') {
3621 p[length - 1] = '\0';
3624 //parse_conky_vars(output, p, cur);
3628 FILE *fp = popen(obj->data.s, "r");
3629 int n2 = fread(p, 1, p_max_size, fp);
3633 if (n2 && p[n2 - 1] == '\n')
3642 if (sscanf(p, "%lf", &barnum) == 0) {
3643 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3645 if (barnum > 100 || barnum < 0) {
3646 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3648 barnum = barnum / 100.0;
3649 new_bar(p, 0, 4, (int) (barnum * 255.0));
3655 FILE *fp = popen(obj->data.s, "r");
3656 int n2 = fread(p, 1, p_max_size, fp);
3660 if (n2 && p[n2 - 1] == '\n')
3669 if (sscanf(p, "%lf", &barnum) == 0) {
3670 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3672 if (barnum > 100 || barnum < 0) {
3673 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3675 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3680 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3681 new_bar(p, 0, 4, (int) obj->f);
3684 FILE *fp = popen(obj->data.execi.cmd, "r");
3685 int n2 = fread(p, 1, p_max_size, fp);
3688 if (n2 && p[n2 - 1] == '\n')
3697 if (sscanf(p, "%f", &barnum) == 0) {
3698 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3700 if (barnum > 100 || barnum < 0) {
3701 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3703 obj->f = 255 * barnum / 100.0;
3704 new_bar(p, 0, 4, (int) obj->f);
3706 obj->data.execi.last_update =
3707 current_update_time;
3711 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3712 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3715 FILE *fp = popen(obj->data.execi.cmd, "r");
3716 int n2 = fread(p, 1, p_max_size, fp);
3719 if (n2 && p[n2 - 1] == '\n')
3728 if (sscanf(p, "%f", &barnum) == 0) {
3729 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3731 if (barnum > 100 || barnum < 0) {
3732 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3735 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3737 obj->data.execi.last_update = current_update_time;
3743 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3744 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3746 char *output = obj->data.execi.buffer;
3747 FILE *fp = popen(obj->data.execi.cmd, "r");
3748 //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
3749 int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
3752 output[length] = '\0';
3753 if (length > 0 && output[length - 1] == '\n') {
3754 output[length - 1] = '\0';
3756 obj->data.execi.last_update = current_update_time;
3757 snprintf(p, p_max_size, "%s", output);
3759 //parse_conky_vars(output, p, cur);
3762 if (obj->data.execi.pos < 0) {
3763 obj->data.execi.last_update = current_update_time;
3764 if (pthread_create(&(obj->data.execi.thread_info.thread), NULL, (void*)threaded_exec, (void*) obj)) {
3765 ERR("Error starting thread");
3767 obj->data.execi.pos = register_thread(&(obj->data.execi.thread_info));
3769 pthread_mutex_lock(&(obj->data.execi.thread_info.mutex));
3770 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3771 pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
3773 #endif /* HAVE_POPEN */
3775 if (obj->global_mode && info.mail) { // this means we use info
3776 if (info.mail->pos < 0) {
3777 info.mail->last_update = current_update_time;
3778 if (pthread_create(&(info.mail->thread_info.thread), NULL, (void*)imap_thread, (void*) info.mail)) {
3779 ERR("Error starting thread");
3781 info.mail->pos = register_thread(&(info.mail->thread_info));
3783 // get a lock before reading
3784 pthread_mutex_lock(&(info.mail->thread_info.mutex));
3785 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3786 pthread_mutex_unlock(&(info.mail->thread_info.mutex));
3787 } else if (obj->data.mail) { // this means we use obj
3788 if (obj->data.mail->pos < 0) {
3789 obj->data.mail->last_update = current_update_time;
3790 if (pthread_create(&(obj->data.mail->thread_info.thread), NULL, (void*)imap_thread, (void*) obj->data.mail)) {
3791 ERR("Error starting thread");
3793 obj->data.mail->pos = register_thread(&(obj->data.mail->thread_info));
3795 pthread_mutex_lock(&(obj->data.mail->thread_info.mutex));
3796 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3797 pthread_mutex_unlock(&(obj->data.mail->thread_info.mutex));
3798 } else if (!obj->a) { // something is wrong, warn once then stop
3799 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3803 OBJ(imap_messages) {
3804 if (obj->global_mode && info.mail) { // this means we use info
3805 if (info.mail->pos < 0) {
3806 info.mail->last_update = current_update_time;
3807 if (pthread_create(&(info.mail->thread_info.thread), NULL, (void*)imap_thread, (void*) info.mail)) {
3808 ERR("Error starting thread");
3810 info.mail->pos = register_thread(&(info.mail->thread_info));
3812 pthread_mutex_lock(&(info.mail->thread_info.mutex));
3813 snprintf(p, p_max_size, "%lu", info.mail->messages);
3814 pthread_mutex_unlock(&(info.mail->thread_info.mutex));
3815 } else if (obj->data.mail) { // this means we use obj
3816 if (obj->data.mail->pos < 0) {
3817 obj->data.mail->last_update = current_update_time;
3818 if (pthread_create(&(obj->data.mail->thread_info.thread), NULL, (void*)imap_thread, (void*) obj->data.mail)) {
3819 ERR("Error starting thread");
3821 obj->data.mail->pos = register_thread(&(obj->data.mail->thread_info));
3823 pthread_mutex_lock(&(obj->data.mail->thread_info.mutex));
3824 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
3825 pthread_mutex_unlock(&(obj->data.mail->thread_info.mutex));
3826 } else if (!obj->a) { // something is wrong, warn once then stop
3827 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3832 if (obj->global_mode && info.mail) { // this means we use info
3833 if (info.mail->pos < 0) {
3834 info.mail->last_update = current_update_time;
3835 if (pthread_create(&(info.mail->thread_info.thread), NULL, (void*)pop3_thread, (void*) info.mail)) {
3836 ERR("Error starting thread");
3838 info.mail->pos = register_thread(&(info.mail->thread_info));
3840 pthread_mutex_lock(&(info.mail->thread_info.mutex));
3841 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3842 pthread_mutex_unlock(&(info.mail->thread_info.mutex));
3843 } else if (obj->data.mail) { // this means we use obj
3844 if (obj->data.mail->pos < 0) {
3845 obj->data.mail->last_update = current_update_time;
3846 if (pthread_create(&(obj->data.mail->thread_info.thread), NULL, (void*)pop3_thread, (void*) obj->data.mail)) {
3847 ERR("Error starting thread");
3849 obj->data.mail->pos = register_thread(&(obj->data.mail->thread_info));
3851 pthread_mutex_lock(&(obj->data.mail->thread_info.mutex));
3852 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3853 pthread_mutex_unlock(&(obj->data.mail->thread_info.mutex));
3854 } else if (!obj->a) { // something is wrong, warn once then stop
3855 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
3860 if (obj->global_mode && info.mail) { // this means we use info
3861 if (info.mail->pos < 0) {
3862 info.mail->last_update = current_update_time;
3863 if (pthread_create(&(info.mail->thread_info.thread), NULL, (void*)pop3_thread, (void*) info.mail)) {
3864 ERR("Error starting thread");
3866 info.mail->pos = register_thread(&(info.mail->thread_info));
3868 pthread_mutex_lock(&(info.mail->thread_info.mutex));
3869 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
3870 pthread_mutex_unlock(&(info.mail->thread_info.mutex));
3871 } else if (obj->data.mail) { // this means we use obj
3872 if (obj->data.mail->pos < 0) {
3873 obj->data.mail->last_update = current_update_time;
3874 if (pthread_create(&(obj->data.mail->thread_info.thread), NULL, (void*)pop3_thread, (void*) obj->data.mail)) {
3875 ERR("Error starting thread");
3877 obj->data.mail->pos = register_thread(&(obj->data.mail->thread_info));
3879 pthread_mutex_lock(&(obj->data.mail->thread_info.mutex));
3880 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
3881 pthread_mutex_unlock(&(obj->data.mail->thread_info.mutex));
3882 } else if (!obj->a) { // something is wrong, warn once then stop
3883 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
3888 if (obj->data.fs != NULL) {
3889 if (obj->data.fs->size == 0)
3908 if (obj->data.fs != NULL)
3909 human_readable(obj->data.fs->avail,
3913 if (obj->data.fs != NULL) {
3914 if (obj->data.fs->size)
3915 snprintf(p, p_max_size, "%*d",
3924 snprintf(p, p_max_size, "0");
3928 if (obj->data.fs != NULL)
3929 human_readable(obj->data.fs->size,
3933 if (obj->data.fs != NULL)
3934 human_readable(obj->data.fs->size -
3935 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
3939 if (obj->data.fs != NULL) {
3940 if (obj->data.fs->size == 0)
3958 if (obj->data.fs != NULL) {
3959 if (obj->data.fs->size)
3960 snprintf(p, 4, "%d",
3970 snprintf(p, p_max_size, "0");
3974 float *v = info.loadavg;
3976 if (obj->data.loadavg[2])
3977 snprintf(p, p_max_size, "%.2f %.2f %.2f",
3978 v[obj->data.loadavg[0] -
3980 v[obj->data.loadavg[1] -
3982 v[obj->data.loadavg[2] -
3984 else if (obj->data.loadavg[1])
3985 snprintf(p, p_max_size, "%.2f %.2f",
3986 v[obj->data.loadavg[0] -
3988 v[obj->data.loadavg[1] -
3990 else if (obj->data.loadavg[0])
3991 snprintf(p, p_max_size, "%.2f",
3992 v[obj->data.loadavg[0] -
3996 new_goto(p, obj->data.i);
3999 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4002 new_hr(p, obj->data.i);
4008 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4009 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4011 snprintf(p, p_max_size, "N/A");
4012 } else if (unit == '*') {
4013 snprintf(p, p_max_size, "%s", temp);
4015 snprintf(p, p_max_size, "%s°%c", temp, unit);
4019 new_offset(p, obj->data.i);
4022 new_voffset(p, obj->data.i);
4027 r = get_i2c_info(&obj->data.i2c.fd,
4029 obj->data.i2c.devtype,
4030 obj->data.i2c.type);
4032 if (r >= 100.0 || r == 0)
4033 snprintf(p, p_max_size, "%d", (int) r);
4035 snprintf(p, p_max_size, "%.1f", r);
4038 new_alignr(p, obj->data.i);
4041 new_alignc(p, obj->data.i);
4045 if ((obj->data.ifblock.s)
4046 && (stat(obj->data.ifblock.s, &tmp) ==
4048 i = obj->data.ifblock.pos;
4055 if ((obj->data.ifblock.s)
4056 && (!check_mount(obj->data.ifblock.s))) {
4057 i = obj->data.ifblock.pos;
4064 if ((obj->data.ifblock.s)
4065 && system(obj->data.ifblock.s)) {
4066 i = obj->data.ifblock.pos;
4073 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4076 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4081 human_readable(cur->mem * 1024, p, 255);
4084 human_readable(cur->memmax * 1024, p, 255);
4089 snprintf(p, p_max_size, "%*lu",
4094 snprintf(p, 4, "%*lu ",
4101 new_bar(p, obj->data.pair.a,
4103 cur->memmax ? (cur->mem * 255) /
4108 new_graph(p, obj->a,
4109 obj->b, obj->c, obj->d,
4110 cur->memmax ? (cur->mem * 100.0) /
4111 (cur->memmax) : 0.0, 100, 1);
4115 snprintf(p, p_max_size, "%d",
4116 mixer_get_avg(obj->data.l));
4119 snprintf(p, p_max_size, "%d",
4120 mixer_get_left(obj->data.l));
4123 snprintf(p, p_max_size, "%d",
4124 mixer_get_right(obj->data.l));
4127 new_bar(p, obj->data.mixerbar.w,
4128 obj->data.mixerbar.h,
4129 mixer_get_avg(obj->data.mixerbar.
4133 new_bar(p, obj->data.mixerbar.w,
4134 obj->data.mixerbar.h,
4135 mixer_get_left(obj->data.mixerbar.
4139 new_bar(p, obj->data.mixerbar.w,
4140 obj->data.mixerbar.h,
4141 mixer_get_right(obj->data.mixerbar.
4147 snprintf(p, p_max_size, "%d", cur->mail_count);
4150 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4153 OBJ(ml_upload_counter) {
4154 snprintf(p, p_max_size, "%lld",
4155 mlinfo.upload_counter / 1048576);
4157 OBJ(ml_download_counter) {
4158 snprintf(p, p_max_size, "%lld",
4159 mlinfo.download_counter /
4162 OBJ(ml_nshared_files) {
4163 snprintf(p, p_max_size, "%i", mlinfo.nshared_files);
4165 OBJ(ml_shared_counter) {
4166 snprintf(p, p_max_size, "%lld",
4167 mlinfo.shared_counter / 1048576);
4169 OBJ(ml_tcp_upload_rate) {
4170 snprintf(p, p_max_size, "%.2f",
4171 (float) mlinfo.tcp_upload_rate /
4174 OBJ(ml_tcp_download_rate) {
4175 snprintf(p, p_max_size, "%.2f",
4176 (float) mlinfo.tcp_download_rate /
4179 OBJ(ml_udp_upload_rate) {
4180 snprintf(p, p_max_size, "%.2f",
4181 (float) mlinfo.udp_upload_rate /
4184 OBJ(ml_udp_download_rate) {
4185 snprintf(p, p_max_size, "%.2f",
4186 (float) mlinfo.udp_download_rate /
4189 OBJ(ml_ndownloaded_files) {
4190 snprintf(p, p_max_size, "%i",
4191 mlinfo.ndownloaded_files);
4193 OBJ(ml_ndownloading_files) {
4194 snprintf(p, p_max_size, "%i",
4195 mlinfo.ndownloading_files);
4200 snprintf(p, p_max_size, "%s",
4201 cur->uname_s.nodename);
4204 new_outline(p, obj->data.l);
4208 snprintf(p, p_max_size, "%hu", cur->procs);
4210 snprintf(p, 5, "%hu ",
4213 OBJ(running_processes) {
4215 snprintf(p, p_max_size, "%hu",
4218 snprintf(p, 3, "%hu ",
4222 snprintf(p, p_max_size, "%s", obj->data.s);
4225 new_bg(p, obj->data.l);
4228 new_stippled_hr(p, obj->data.pair.a,
4232 human_readable(cur->swap * 1024, p, 255);
4235 human_readable(cur->swapmax * 1024, p,
4239 if (cur->swapmax == 0) {
4240 strncpy(p, "No swap", 255);
4243 snprintf(p, 255, "%*lu",
4249 snprintf(p, 4, "%*lu ",
4257 new_bar(p, obj->data.pair.a,
4259 cur->swapmax ? (cur->swap * 255) /
4260 (cur->swapmax) : 0);
4263 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4266 time_t t = time(NULL);
4267 struct tm *tm = localtime(&t);
4268 setlocale(LC_TIME, "");
4269 strftime(p, p_max_size, obj->data.s, tm);
4272 time_t t = time(NULL);
4273 struct tm *tm = gmtime(&t);
4274 strftime(p, p_max_size, obj->data.s, tm);
4278 if (obj->data.tztime.tz) {
4279 oldTZ = getenv("TZ");
4280 setenv("TZ", obj->data.tztime.tz, 1);
4283 time_t t = time(NULL);
4284 struct tm *tm = localtime(&t);
4285 setlocale(LC_TIME, "");
4286 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4288 setenv("TZ", oldTZ, 1);
4293 // Needless to free oldTZ since getenv gives ptr to static data
4296 human_readable(obj->data.net->recv, p,
4300 human_readable(obj->data.net->trans, p,
4304 snprintf(p, p_max_size, "%d", total_updates);
4308 snprintf(p, p_max_size, "%d",
4309 (int) (obj->data.net->
4313 snprintf(p, 5, "%d ",
4314 (int) (obj->data.net->
4320 snprintf(p, p_max_size, "%.1f",
4322 trans_speed / 1024.0);
4324 snprintf(p, 8, "%.1f ",
4326 trans_speed / 1024.0);
4329 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
4330 obj->data.net->trans_speed = 0.01;
4331 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4332 (obj->data.net->trans_speed /
4333 1024.0), obj->e, 1);
4336 format_seconds_short(p, p_max_size,
4340 format_seconds(p, p_max_size, (int) cur->uptime);
4343 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
4345 snprintf(p, p_max_size, "%s", get_apm_adapter());
4347 OBJ(apm_battery_life) {
4349 msg = get_apm_battery_life();
4350 snprintf(p, p_max_size, "%s", msg);
4353 OBJ(apm_battery_time) {
4355 msg = get_apm_battery_time();
4356 snprintf(p, p_max_size, "%s", msg);
4359 #endif /* __FreeBSD__ */
4362 snprintf(p, p_max_size, "%.2f",
4363 cur->seti_prog * 100.0f);
4366 new_bar(p, obj->data.pair.a,
4368 (int) (cur->seti_prog * 255.0f));
4371 snprintf(p, p_max_size, "%.0f", cur->seti_credit);
4377 snprintf(p, p_max_size, "%s", cur->mpd.title);
4380 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4383 snprintf(p, p_max_size, "%s", cur->mpd.album);
4386 snprintf(p, p_max_size, "%s", cur->mpd.random);
4389 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4392 snprintf(p, p_max_size, "%s", cur->mpd.track);
4395 snprintf(p, p_max_size, "%s", cur->mpd.name);
4398 snprintf(p, p_max_size, "%s", cur->mpd.file);
4401 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4404 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4407 snprintf(p, p_max_size, "%s", cur->mpd.status);
4410 int days = 0, hours = 0, minutes =
4412 int tmp = cur->mpd.elapsed;
4413 while (tmp >= 86400) {
4417 while (tmp >= 3600) {
4427 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4428 days, hours, minutes,
4431 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4434 snprintf(p, p_max_size, "%i:%02i", minutes,
4438 int days = 0, hours = 0, minutes =
4440 int tmp = cur->mpd.length;
4441 while (tmp >= 86400) {
4445 while (tmp >= 3600) {
4455 snprintf(p, p_max_size,
4456 "%i days %i:%02i:%02i",
4457 days, hours, minutes,
4460 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4463 snprintf(p, p_max_size, "%i:%02i", minutes,
4467 snprintf(p, p_max_size, "%2.0f",
4468 cur->mpd.progress * 100);
4471 new_bar(p, obj->data.pair.a,
4473 (int) (cur->mpd.progress *
4477 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4478 snprintf(p, p_max_size, "%s", cur->mpd.file);
4480 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4486 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4489 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4492 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4495 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4497 OBJ(xmms2_comment) {
4498 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4500 OBJ(xmms2_decoder) {
4501 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4503 OBJ(xmms2_transport) {
4504 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4507 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4510 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4513 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4515 OBJ(xmms2_tracknr) {
4516 if (cur->xmms2.tracknr != -1)
4517 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4519 OBJ(xmms2_bitrate) {
4520 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4523 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4526 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4528 OBJ(xmms2_elapsed) {
4529 int tmp = cur->xmms2.elapsed;
4530 snprintf(p, p_max_size, "%02d:%02d",
4531 tmp / 60000, (tmp / 1000) % 60);
4533 OBJ(xmms2_duration) {
4534 int tmp = cur->xmms2.duration;
4535 snprintf(p, p_max_size, "%02d:%02d",
4536 tmp / 60000, (tmp / 1000) % 60);
4538 OBJ(xmms2_percent) {
4539 snprintf(p, p_max_size, "%2.0f",
4540 cur->xmms2.progress * 100);
4543 new_bar(p, obj->data.pair.a,
4545 (int) (cur->xmms2.progress *
4549 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4550 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4552 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4556 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4558 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_STATUS]);
4561 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_TITLE]);
4564 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH]);
4566 OBJ(xmms_length_seconds) {
4567 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH_SECONDS]);
4569 OBJ(xmms_position) {
4570 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION]);
4572 OBJ(xmms_position_seconds) {
4573 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION_SECONDS]);
4576 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_BITRATE]);
4578 OBJ(xmms_frequency) {
4579 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FREQUENCY]);
4581 OBJ(xmms_channels) {
4582 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_CHANNELS]);
4584 OBJ(xmms_filename) {
4585 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FILENAME]);
4587 OBJ(xmms_playlist_length) {
4588 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_LENGTH]);
4590 OBJ(xmms_playlist_position) {
4591 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_POSITION]);
4595 progress= atof(cur->xmms.items[XMMS_POSITION_SECONDS]) /
4596 atof(cur->xmms.items[XMMS_LENGTH_SECONDS]);
4597 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4602 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4605 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4608 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4611 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4614 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4617 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4621 if (obj->data.top.type == TOP_NAME
4622 && obj->data.top.num >= 0
4623 && obj->data.top.num < 10) {
4624 // if we limit the buffer and add a bunch of space after, it stops the thing from
4625 // moving other shit around, which is really fucking annoying
4626 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4627 } else if (obj->data.top.type == TOP_CPU
4628 && obj->data.top.num >= 0
4629 && obj->data.top.num < 10) {
4630 snprintf(p, 7, "%3.2f ",
4631 cur->cpu[obj->data.top.
4633 } else if (obj->data.top.type == TOP_PID
4634 && obj->data.top.num >= 0
4635 && obj->data.top.num < 10) {
4636 snprintf(p, 8, "%i ",
4637 cur->cpu[obj->data.top.
4639 } else if (obj->data.top.type == TOP_MEM
4640 && obj->data.top.num >= 0
4641 && obj->data.top.num < 10) {
4642 snprintf(p, 7, "%3.2f ",
4643 cur->cpu[obj->data.top.
4648 if (obj->data.top.type == TOP_NAME
4649 && obj->data.top.num >= 0
4650 && obj->data.top.num < 10) {
4651 // if we limit the buffer and add a bunch of space after, it stops the thing from
4652 // moving other shit around, which is really fucking annoying
4655 cur->memu[obj->data.top.
4657 } else if (obj->data.top.type == TOP_CPU
4658 && obj->data.top.num >= 0
4659 && obj->data.top.num < 10) {
4660 snprintf(p, 7, "%3.2f ",
4661 cur->memu[obj->data.top.
4663 } else if (obj->data.top.type == TOP_PID
4664 && obj->data.top.num >= 0
4665 && obj->data.top.num < 10) {
4666 snprintf(p, 8, "%i ",
4667 cur->memu[obj->data.top.
4669 } else if (obj->data.top.type == TOP_MEM
4670 && obj->data.top.num >= 0
4671 && obj->data.top.num < 10) {
4672 snprintf(p, 7, "%3.2f ",
4673 cur->memu[obj->data.top.
4680 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4681 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4683 obj->data.tail.last_update = current_update_time;
4687 tailstring *head = NULL;
4688 tailstring *headtmp = NULL;
4689 tailstring *freetmp = NULL;
4690 fp = fopen(obj->data.tail.logfile, "rt");
4692 ERR("tail logfile failed to open");
4695 obj->data.tail.readlines = 0;
4697 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
4704 addtail(&head, obj->data.tail.buffer);
4705 obj->data.tail.readlines++;
4711 if (obj->data.tail.readlines > 0) {
4712 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
4713 addtail(&headtmp, head->data);
4718 strcpy(obj->data.tail.buffer, headtmp->data);
4719 headtmp = headtmp->next;
4720 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
4722 strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
4723 headtmp = headtmp->next;
4727 /* get rid of any ugly newlines at the end */
4728 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
4729 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
4731 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4735 strcpy(obj->data.tail.buffer, "Logfile Empty");
4736 snprintf(p, p_max_size, "Logfile Empty");
4737 } /* if readlines */
4739 } /* if cur_upd_time >= */
4741 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4745 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4746 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4748 obj->data.tail.last_update = current_update_time;
4750 tailstring *head = NULL;
4751 tailstring *headtmp = NULL;
4752 tailstring *freetmp = NULL;
4753 fp = fopen(obj->data.tail.logfile, "rt");
4755 ERR("head logfile failed to open");
4757 obj->data.tail.readlines = 0;
4758 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
4759 addtail(&head, obj->data.tail.buffer);
4760 obj->data.tail.readlines++;
4764 if (obj->data.tail.readlines > 0) {
4766 addtail(&headtmp, head->data);
4771 strcpy(obj->data.tail.buffer, headtmp->data);
4772 headtmp = headtmp->next;
4774 strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
4775 headtmp = headtmp->next;
4778 /* get rid of any ugly newlines at the end */
4779 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
4780 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
4782 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4784 strcpy(obj->data.tail.buffer, "Logfile Empty");
4785 snprintf(p, p_max_size, "Logfile Empty");
4786 } /* if readlines > 0 */
4787 } /* if fp == null */
4788 } /* cur_upd_time >= */
4790 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4793 #ifdef TCP_PORT_MONITOR
4796 /* grab a pointer to this port monitor */
4797 tcp_port_monitor_t * p_monitor =
4798 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
4799 obj->data.tcp_port_monitor.port_range_begin,
4800 obj->data.tcp_port_monitor.port_range_end );
4802 snprintf(p, p_max_size, "monitor not found");
4806 /* now grab the text of interest */
4807 if ( peek_tcp_port_monitor( p_monitor,
4808 obj->data.tcp_port_monitor.item,
4809 obj->data.tcp_port_monitor.connection_index,
4810 p, p_max_size ) != 0 )
4812 snprintf(p, p_max_size, "monitor peek error");
4821 iconv_converting = 1;
4822 iconv_selected = obj->a;
4827 iconv_converting = 0;
4836 unsigned int a = strlen(p);
4839 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
4841 size_t dummy1, dummy2;
4842 char *ptr = buff_in;
4845 dummy1 = dummy2 = a;
4847 strncpy(buff_in, p, P_MAX_SIZE);
4849 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
4850 while (dummy1 > 0) {
4851 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
4853 ERR("Iconv codeset conversion failed");
4858 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
4869 double current_update_time, last_update_time;
4871 static void generate_text()
4873 struct information *cur = &info;
4881 current_update_time = get_time();
4885 /* add things to the buffer */
4891 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
4893 if (stuff_in_upper_case) {
4904 last_update_time = current_update_time;
4911 static void set_font()
4915 if (window.xftdraw != NULL) {
4916 XftDrawDestroy(window.xftdraw);
4918 window.xftdraw = XftDrawCreate(display, window.drawable,
4919 DefaultVisual(display,
4921 DefaultColormap(display,
4926 XSetFont(display, window.gc, fonts[selected_font].font->fid);
4932 static inline int get_string_width(const char *s)
4935 return *s ? calc_text_width(s, strlen(s)) : 0;
4941 static inline int get_string_width_special(char *s)
4954 if (*p == SPECIAL_CHAR) {
4955 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
4956 for (i = 0; i < strlen(p); i++) {
4957 *(p + i) = *(p + i + 1);
4959 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
4960 width += specials[special_index+index].width;
4967 if (strlen(final) > 1) {
4968 width += calc_text_width(final, strlen(final));
4978 static void text_size_updater(char *s);
4980 int last_font_height;
4981 static void update_text_area()
4985 /* update text size if it isn't fixed */
4990 text_width = minimum_width;
4993 int first_font_height = last_font_height = font_height();
4994 for_each_line(text_buffer, text_size_updater);
4995 text_height -= first_font_height;
4997 if (text_height < minimum_height)
4998 text_height = minimum_height;
4999 if (text_width > maximum_width && maximum_width > 0)
5000 text_width = maximum_width;
5003 /* get text position on workarea */
5004 switch (text_alignment) {
5011 x = workarea[2] - text_width - gap_x;
5018 y = workarea[3] - text_height - gap_y;
5022 x = workarea[2] - text_width - gap_x;
5023 y = workarea[3] - text_height - gap_y;
5027 case NONE: // Let the WM manage the window
5038 if (own_window && !fixed_pos) {
5041 text_start_x = border_margin + 1;
5042 text_start_y = border_margin + 1;
5043 window.x = x - border_margin - 1;
5044 window.y = y - border_margin - 1;
5048 /* If window size doesn't match to workarea's size, then window
5049 * probably includes panels (gnome).
5050 * Blah, doesn't work on KDE. */
5051 if (workarea[2] != window.width
5052 || workarea[3] != window.height) {
5066 static int cur_x, cur_y; /* current x and y for drawing */
5067 static int draw_mode; /* FG, BG or OUTLINE */
5068 static long current_color;
5071 static void text_size_updater(char *s)
5075 /* get string widths and skip specials */
5078 if (*p == SPECIAL_CHAR) {
5080 w += get_string_width(s);
5083 if (specials[special_index].type == BAR
5084 || specials[special_index].type == GRAPH) {
5085 w += specials[special_index].width;
5086 if (specials[special_index].height > last_font_height) {
5087 last_font_height = specials[special_index].height;
5088 last_font_height += font_ascent();
5090 } else if (specials[special_index].type == OFFSET) {
5091 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5092 } else if (specials[special_index].type == VOFFSET) {
5093 last_font_height += specials[special_index].arg;
5094 } else if (specials[special_index].type == GOTO) {
5095 if (specials[special_index].arg >= 0)
5096 w += (int)specials[special_index].arg - cur_x;
5097 } else if (specials[special_index].type == TAB) {
5098 int start = specials[special_index].arg;
5099 int step = specials[special_index].width;
5100 if (!step || step < 0)
5102 w += step - (cur_x - text_start_x - start) % step;
5103 } else if (specials[special_index].type == FONT) {
5104 selected_font = specials[special_index].font_added;
5105 if (font_height() > last_font_height) {
5106 last_font_height = font_height();
5115 w += get_string_width(s);
5116 if (w > text_width) {
5119 if (text_width > maximum_width && maximum_width) {
5120 text_width = maximum_width;
5123 text_height += last_font_height;
5124 last_font_height = font_height();
5128 static inline void set_foreground_color(long c)
5131 XSetForeground(display, window.gc, c);
5135 static void draw_string(const char *s)
5139 int i, i2, pos, width_of_s;
5142 width_of_s = get_string_width(s);
5143 if (out_to_console) {
5145 fflush(stdout); /* output immediately, don't buffer */
5147 /* 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 */
5148 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5149 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5150 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5154 snprintf(space, 2, " ");
5156 max = ((text_width - width_of_s) / get_string_width(space));
5159 * This code looks for tabs in the text and coverts them to spaces.
5160 * The trick is getting the correct number of spaces,
5161 * and not going over the window's size without forcing
5162 * the window larger.
5164 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5165 if (tmpstring1[i] == '\t') // 9 is ascii tab
5169 i2 < (8 - (1 + pos) % 8) && added <= max;
5172 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5173 fprintf(stderr,"buffer overrun detected\n");
5175 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5180 if (tmpstring1[i] != 9) {
5182 if ( pos > TEXT_BUFFER_SIZE-1 )
5183 fprintf(stderr,"buffer overrun detected\n");
5185 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5191 if (text_width == maximum_width) {
5192 /* this means the text is probably pushing the limit, so we'll chop it */
5193 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5194 tmpstring2[strlen(tmpstring2)-1] = '\0';
5204 c.pixel = current_color;
5205 XQueryColor(display, DefaultColormap(display, screen), &c);
5208 c2.color.red = c.red;
5209 c2.color.green = c.green;
5210 c2.color.blue = c.blue;
5211 c2.color.alpha = fonts[selected_font].font_alpha;
5213 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5214 cur_x, cur_y, (XftChar8 *) s,
5217 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5218 cur_x, cur_y, (XftChar8 *) s,
5224 XDrawString(display, window.drawable, window.gc,
5225 cur_x, cur_y, s, strlen(s));
5227 cur_x += width_of_s;
5229 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5232 long redmask, greenmask, bluemask;
5234 void set_up_gradient()
5237 colour_depth = DisplayPlanes(display, screen);
5241 if (colour_depth != 24 && colour_depth != 16) {
5242 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5248 for(i = (colour_depth / 3)-1; i>=0; i--) {
5250 greenmask |= 1 << i;
5253 if (colour_depth%3 == 1) {
5254 greenmask |= 1 << (colour_depth / 3);
5256 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5257 greenmask = greenmask << (colour_depth / 3);
5260 inline unsigned long do_gradient(unsigned long first_colour, unsigned long last_colour) { /* this function returns the next colour between two colours for a gradient */
5262 int red1, green1, blue1; // first colour
5263 int red2, green2, blue2; // second colour
5264 int red3 = 0, green3 = 0, blue3 = 0; // difference
5265 short redshift = (2*colour_depth / 3 + colour_depth%3);
5266 short greenshift = (colour_depth / 3);
5267 red1 = (first_colour & redmask) >> redshift;
5268 green1 = (first_colour & greenmask) >> greenshift;
5269 blue1 = first_colour & bluemask;
5270 red2 = (last_colour & redmask) >> redshift;
5271 green2 = (last_colour & greenmask) >> greenshift;
5272 blue2 = last_colour & bluemask;
5279 if (green1 > green2) {
5282 if (green1 < green2) {
5285 if (blue1 > blue2) {
5288 if (blue1 < blue2) {
5303 if (red1 > bluemask) {
5306 if (green1 > bluemask) {
5309 if (blue1 > bluemask) {
5312 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5316 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5317 if (colour_depth == 0) {
5320 int red1, green1, blue1; // first colour
5321 int red2, green2, blue2; // second colour
5322 long redshift = (2*colour_depth / 3 + colour_depth%3);
5323 long greenshift = (colour_depth / 3);
5324 int red3 = 0, green3 = 0, blue3 = 0; // difference
5325 red1 = (first_colour & redmask) >> redshift;
5326 green1 = (first_colour & greenmask) >> greenshift;
5327 blue1 = first_colour & bluemask;
5328 red2 = (last_colour & redmask) >> redshift;
5329 green2 = (last_colour & greenmask) >> greenshift;
5330 blue2 = last_colour & bluemask;
5331 red3 = abs(red1 - red2);
5332 green3 = abs(green1 - green2);
5333 blue3 = abs(blue1 - blue2);
5342 static void draw_line(char *s)
5346 cur_x = text_start_x;
5347 cur_y += font_ascent();
5349 short font_h = font_height();
5351 /* find specials and draw stuff */
5354 if (*p == SPECIAL_CHAR) {
5357 /* draw string before special */
5364 switch (specials[special_index].type) {
5365 case HORIZONTAL_LINE:
5368 specials[special_index].height;
5369 int mid = font_ascent() / 2;
5370 w = text_start_x + text_width -
5373 XSetLineAttributes(display,
5378 XDrawLine(display, window.drawable,
5389 specials[special_index].height;
5391 specials[special_index].arg;
5392 int mid = font_ascent() / 2;
5393 char ss[2] = { s, s };
5394 w = text_start_x + text_width -
5397 XSetLineAttributes(display,
5402 XSetDashes(display, window.gc, 0,
5404 XDrawLine(display, window.drawable,
5414 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5418 specials[special_index].height;
5420 specials[special_index].arg;
5421 int by = cur_y - (font_ascent() / 2) - 1;
5422 if (h < font_height()) {
5425 w = specials[special_index].width;
5428 text_width - cur_x - 1;
5432 XSetLineAttributes(display,
5438 XDrawRectangle(display,
5442 XFillRectangle(display,
5446 w * bar_usage / 255,
5448 if (specials[special_index].
5450 && specials[special_index].
5454 [special_index].height;
5461 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5465 specials[special_index].height;
5466 unsigned long last_colour = current_color;
5467 int by = cur_y - (font_ascent()/2) - 1;
5468 if (h < font_height()) {
5471 w = specials[special_index].width;
5473 w = text_start_x + text_width - cur_x - 1;
5476 if (draw_graph_borders) {
5477 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5478 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5480 XSetLineAttributes(display,
5487 int gradient_size = 0;
5488 float gradient_factor = 0;
5489 float gradient_update = 0;
5490 unsigned long tmpcolour = current_color;
5491 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5492 tmpcolour = specials[special_index].last_colour;
5493 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5494 gradient_factor = (float)gradient_size / (w - 2);
5496 for (i = w - 2; i > -1; i--) {
5497 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5498 XSetForeground(display, window.gc, tmpcolour);
5499 gradient_update += gradient_factor;
5500 while (gradient_update > 0) {
5501 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5505 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5508 XDrawLine(display, window.drawable, window.gc, cur_x + i + 1, by + h, cur_x + i + 1, by + h - specials[special_index].graph[j] * (h - 1) / specials[special_index].graph_scale); /* this is mugfugly, but it works */
5510 if (specials[special_index].
5512 && specials[special_index].
5516 [special_index].height;
5518 /* if (draw_mode == BG) {
5519 set_foreground_color(default_bg_color);
5521 else if (draw_mode == OUTLINE) {
5522 set_foreground_color(default_out_color);
5524 set_foreground_color(default_fg_color);
5526 set_foreground_color(last_colour);
5532 int old = font_ascent();
5533 cur_y -= font_ascent();
5534 selected_font = specials[special_index].font_added;
5535 if (cur_y + font_ascent() < cur_y + old) {
5538 cur_y += font_ascent();
5544 if (draw_mode == FG)
5545 set_foreground_color(specials
5551 if (draw_mode == BG)
5552 set_foreground_color(specials
5558 if (draw_mode == OUTLINE)
5559 set_foreground_color(specials
5565 w += specials[special_index].arg;
5569 cur_y += specials[special_index].arg;
5573 if (specials[special_index].arg >= 0)
5574 cur_x = (int)specials[special_index].arg;
5579 int start = specials[special_index].arg;
5580 int step = specials[special_index].width;
5581 if (!step || step < 0)
5583 w = step - (cur_x - text_start_x - start) % step;
5589 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5590 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, specials[special_index].arg, border_margin, border_width);*/
5591 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5592 cur_x = pos_x - specials[special_index].arg;
5599 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5600 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5601 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, specials[special_index].arg);*/
5603 specials[special_index].arg)
5606 [special_index].arg;
5623 if (cur_y_add > 0) {
5625 cur_y -= font_descent();
5630 cur_y += font_descent();
5634 static void draw_text()
5637 cur_y = text_start_y;
5640 if (draw_borders && border_width > 0) {
5641 unsigned int b = (border_width + 1) / 2;
5643 if (stippled_borders) {
5645 { stippled_borders, stippled_borders };
5646 XSetLineAttributes(display, window.gc,
5647 border_width, LineOnOffDash,
5648 CapButt, JoinMiter);
5649 XSetDashes(display, window.gc, 0, ss, 2);
5651 XSetLineAttributes(display, window.gc,
5652 border_width, LineSolid,
5653 CapButt, JoinMiter);
5656 XDrawRectangle(display, window.drawable, window.gc,
5657 text_start_x - border_margin + b,
5658 text_start_y - border_margin + b,
5659 text_width + border_margin * 2 - 1 - b * 2,
5660 text_height + border_margin * 2 - 1 -
5667 for_each_line(text_buffer, draw_line);
5670 static void draw_stuff()
5674 if (draw_shades && !draw_outline) {
5677 set_foreground_color(default_bg_color);
5687 for (i = -1; i < 2; i++)
5688 for (j = -1; j < 2; j++) {
5689 if (i == 0 && j == 0)
5693 set_foreground_color(default_out_color);
5694 draw_mode = OUTLINE;
5701 set_foreground_color(default_fg_color);
5709 swap.swap_window = window.window;
5710 swap.swap_action = XdbeBackground;
5711 XdbeSwapBuffers(display, &swap, 1);
5717 static void clear_text(int exposures)
5721 return; /* The swap action is XdbeBackground, which clears */
5725 /* there is some extra space for borders and outlines */
5726 XClearArea(display, window.drawable,
5727 text_start_x - border_margin - 1,
5728 text_start_y - border_margin - 1,
5729 text_width + border_margin * 2 + 2,
5730 text_height + border_margin * 2 + 2,
5731 exposures ? True : 0);
5736 static int need_to_update;
5738 /* update_text() generates new text and clears old text area */
5739 static void update_text()
5748 static void main_loop()
5750 #ifdef SIGNAL_BLOCKING
5751 sigset_t newmask, oldmask;
5753 sigemptyset(&newmask);
5754 sigaddset(&newmask,SIGINT);
5755 sigaddset(&newmask,SIGTERM);
5756 sigaddset(&newmask,SIGUSR1);
5760 Region region = XCreateRegion();
5761 int event_base, error_base;
5763 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
5764 ERR("Xdamage extension unavailable");
5766 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
5767 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
5768 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
5769 #endif /* HAVE_XDAMAGE */
5773 while (total_run_times == 0 || info.looped < total_run_times) {
5776 #ifdef SIGNAL_BLOCKING
5777 /* block signals. we will inspect for pending signals later */
5778 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
5779 CRIT_ERR("unable to sigprocmask()");
5785 /* wait for X event or timeout */
5787 if (!XPending(display)) {
5792 update_interval - (get_time() -
5798 tv.tv_sec = (long) t;
5799 tv.tv_usec = (long) (t * 1000000) % 1000000;
5801 FD_SET(ConnectionNumber(display), &fdsr);
5804 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
5807 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
5812 ERR("can't select(): %s",
5823 if (need_to_update) {
5825 int wx = window.x, wy = window.y;
5833 /* resize window if it isn't right size */
5835 (text_width + border_margin * 2 + 1 !=
5837 || text_height + border_margin * 2 + 1 !=
5841 border_margin * 2 + 1;
5844 border_margin * 2 + 1;
5845 XResizeWindow(display,
5850 set_transparent_background(window.drawable);
5854 /* move window if it isn't in right position */
5857 || window.y != wy)) {
5858 XMoveWindow(display, window.window,
5859 window.x, window.y);
5869 r.x = text_start_x - border_margin;
5870 r.y = text_start_y - border_margin;
5871 r.width = text_width + border_margin * 2;
5872 r.height = text_height + border_margin * 2;
5873 XUnionRectWithRegion(&r, region, region);
5878 /* handle X events */
5880 while (XPending(display)) {
5882 XNextEvent(display, &ev);
5889 r.width = ev.xexpose.width;
5890 r.height = ev.xexpose.height;
5891 XUnionRectWithRegion(&r, region,
5897 case ReparentNotify:
5898 /* set background to ParentRelative for all parents */
5900 set_transparent_background(window.
5905 case ConfigureNotify:
5907 /* if window size isn't what expected, set fixed size */
5908 if (ev.xconfigure.width !=
5910 || ev.xconfigure.height !=
5912 if (window.width != 0
5913 && window.height != 0)
5916 /* clear old stuff before screwing up size and pos */
5922 if (XGetWindowAttributes(display, window.window, &attrs)) {
5937 border_margin * 2 - 1;
5940 border_margin * 2 - 1;
5941 if (text_width > maximum_width && maximum_width > 0)
5942 text_width = maximum_width;
5945 /* if position isn't what expected, set fixed pos, total_updates
5946 * avoids setting fixed_pos when window is set to weird locations
5948 /*if (total_updates >= 2 this is broken
5950 && (window.x != ev.xconfigure.x
5953 && (ev.xconfigure.x != 0
5954 || ev.xconfigure.y != 0)) {
5964 /* forward the click to the desktop window */
5965 XUngrabPointer(display, ev.xbutton.time);
5966 ev.xbutton.window = window.desktop;
5967 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
5974 /* forward the release to the desktop window */
5975 ev.xbutton.window = window.desktop;
5976 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
5984 if (ev.type == event_base + XDamageNotify) {
5985 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
5986 XFixesSetRegion(display, part, &dev->area, 1);
5987 XFixesUnionRegion(display, region2, region2, part);
5988 XDamageSubtract(display, damage, region2, None);
5989 XFixesSetRegion(display, region2, 0, 0);
5991 #endif /* HAVE_XDAMAGE */
5996 /* XDBE doesn't seem to provide a way to clear the back buffer without
5997 * interfering with the front buffer, other than passing XdbeBackground
5998 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
5999 * redraw the text even if it wasn't part of the exposed area. OTOH,
6000 * if we're not going to call draw_stuff at all, then no swap happens
6001 * and we can safely do nothing.
6004 if (!XEmptyRegion(region)) {
6008 r.x = text_start_x - border_margin;
6009 r.y = text_start_y - border_margin;
6010 r.width = text_width + border_margin * 2;
6011 r.height = text_height + border_margin * 2;
6012 XUnionRectWithRegion(&r, region, region);
6015 XSetRegion(display, window.gc, region);
6018 XftDrawSetClip(window.xftdraw, region);
6024 XDestroyRegion(region);
6025 region = XCreateRegion();
6029 #ifdef SIGNAL_BLOCKING
6030 /* unblock signals of interest and let handler fly */
6031 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6032 CRIT_ERR("unable to sigprocmask()");
6035 switch(g_signal_pending) {
6038 ERR("received SIGUSR1. reloading the config file.");
6045 ERR("received SIGINT or SIGTERM to terminate. bye!");
6048 XDestroyRegion(region);
6051 return; /* return from main_loop */
6056 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6057 * but didn't write any code to deal with it. if you don't want to
6058 * handle a signal, don't set a handler on it in the first place. */
6059 if (g_signal_pending)
6060 ERR("ignoring signal (%d)", g_signal_pending);
6067 #if defined(X11) && defined(HAVE_XDAMAGE)
6068 XDamageDestroy(display, damage);
6069 XFixesDestroyRegion(display, region2);
6070 XFixesDestroyRegion(display, part);
6071 XDestroyRegion(region);
6073 #endif /* X11 && HAVE_XDAMAGE */
6076 static void load_config_file(const char *);
6078 /* reload the config file */
6079 void reload_config(void)
6081 //lock_all_threads();
6083 if (info.cpu_usage) {
6084 free(info.cpu_usage);
6085 info.cpu_usage = NULL;
6087 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
6088 if (info.xmms.thread) {
6089 if (destroy_xmms_thread()!=0)
6091 ERR("error destroying xmms_player thread");
6095 #ifdef TCP_PORT_MONITOR
6096 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6099 if (current_config) {
6101 load_config_file(current_config);
6105 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6108 #ifdef TCP_PORT_MONITOR
6109 info.p_tcp_port_monitor_collection = NULL;
6111 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
6112 if ( (!info.xmms.thread) && (info.xmms.current_project > PROJECT_NONE) &&
6113 (create_xmms_thread() !=0) )
6115 CRIT_ERR("unable to create xmms_player thread!");
6118 extract_variable_text(text);
6128 //lock_all_threads();
6130 if (info.cpu_usage) {
6131 free(info.cpu_usage);
6132 info.cpu_usage = NULL;
6137 XdbeDeallocateBackBufferName(display, window.back_buffer);
6143 XDestroyWindow(display, window.window);
6144 XClearWindow(display, RootWindow(display, screen));
6150 XClearWindow(display, RootWindow(display, screen));
6155 XFreeGC(display, window.gc);
6159 /* it is really pointless to free() memory at the end of program but ak|ra
6160 * wants me to do this */
6162 free_text_objects(text_object_count, text_objects);
6163 text_object_count = 0;
6164 text_objects = NULL;
6168 #endif /* MLDONKEY */
6170 if (text != original_text)
6173 free(current_config);
6174 free(current_mail_spool);
6178 #ifdef TCP_PORT_MONITOR
6179 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6180 info.p_tcp_port_monitor_collection = NULL;
6182 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
6183 if ( info.xmms.thread && (destroy_xmms_thread()!=0) )
6185 ERR("error destroying xmms_player thread");
6190 static int string_to_bool(const char *s)
6194 if (strcasecmp(s, "yes") == 0)
6196 if (strcasecmp(s, "true") == 0)
6198 if (strcasecmp(s, "1") == 0)
6203 static enum alignment string_to_alignment(const char *s)
6205 if (strcasecmp(s, "top_left") == 0)
6207 else if (strcasecmp(s, "top_right") == 0)
6209 else if (strcasecmp(s, "bottom_left") == 0)
6211 else if (strcasecmp(s, "bottom_right") == 0)
6212 return BOTTOM_RIGHT;
6213 else if (strcasecmp(s, "tl") == 0)
6215 else if (strcasecmp(s, "tr") == 0)
6217 else if (strcasecmp(s, "bl") == 0)
6219 else if (strcasecmp(s, "br") == 0)
6220 return BOTTOM_RIGHT;
6221 else if (strcasecmp(s, "none") == 0)
6228 static void set_default_configurations(void)
6230 fork_to_background = 0;
6231 total_run_times = 0;
6232 info.cpu_avg_samples = 2;
6233 info.net_avg_samples = 2;
6238 strcpy(info.mpd.host, "localhost");
6239 info.mpd.port = 6600;
6240 info.mpd.status = NULL;
6241 info.mpd.artist = NULL;
6242 info.mpd.album = NULL;
6243 info.mpd.title = NULL;
6244 info.mpd.random = NULL;
6245 info.mpd.track = NULL;
6246 info.mpd.name = NULL;
6247 info.mpd.file = NULL;
6250 info.xmms2.artist = NULL;
6251 info.xmms2.album = NULL;
6252 info.xmms2.title = NULL;
6253 info.xmms2.genre = NULL;
6254 info.xmms2.comment = NULL;
6255 info.xmms2.decoder = NULL;
6256 info.xmms2.transport = NULL;
6257 info.xmms2.url = NULL;
6258 info.xmms2.status = NULL;
6267 default_fg_color = WhitePixel(display, screen);
6268 default_bg_color = BlackPixel(display, screen);
6269 default_out_color = BlackPixel(display, screen);
6272 draw_graph_borders = 1;
6274 set_first_font("6x10");
6282 window.type=TYPE_NORMAL;
6284 strcpy(window.wm_class_name, "conky");
6286 stippled_borders = 0;
6289 text_alignment = BOTTOM_LEFT;
6293 free(current_mail_spool);
6296 variable_substitute(MAIL_FILE, buf, 256);
6298 current_mail_spool = strdup(buf);
6302 update_interval = 10.0;
6303 stuff_in_upper_case = 0;
6305 mlconfig.mldonkey_hostname = strdup("127.0.0.1");
6306 mlconfig.mldonkey_port = 4001;
6307 mlconfig.mldonkey_login = NULL;
6308 mlconfig.mldonkey_password = NULL;
6311 #ifdef TCP_PORT_MONITOR
6312 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6313 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6316 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
6317 info.xmms.current_project=PROJECT_NONE;
6321 static void load_config_file(const char *f)
6323 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6327 set_default_configurations();
6333 char buf[256], *p, *p2, *name, *value;
6335 if (fgets(buf, 256, fp) == NULL)
6340 /* break at comment */
6341 p2 = strchr(p, '#');
6346 while (*p && isspace((int) *p))
6349 continue; /* empty line */
6355 while (*p2 && !isspace((int) *p2))
6358 *p2 = '\0'; /* break at name's end */
6365 while (*p && isspace((int) *p))
6370 p2 = value + strlen(value);
6371 while (isspace((int) *(p2 - 1)))
6377 #define CONF2(a) if (strcasecmp(name, a) == 0)
6378 #define CONF(a) else CONF2(a)
6379 #define CONF3(a,b) \
6380 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6384 CONF2("alignment") {
6386 int a = string_to_alignment(value);
6396 ERR("on_bottom is deprecated. use own_window_hints below");
6397 on_bottom = string_to_bool(value);
6399 SET_HINT(window.hints,HINT_BELOW);
6404 CONF("background") {
6405 fork_to_background = string_to_bool(value);
6409 CONF2("background") {
6410 fork_to_background = string_to_bool(value);
6414 CONF("border_margin") {
6416 border_margin = strtol(value, 0, 0);
6420 CONF("border_width") {
6422 border_width = strtol(value, 0, 0);
6426 CONF("default_color") {
6428 default_fg_color = get_x11_color(value);
6432 CONF3("default_shade_color", "default_shadecolor") {
6434 default_bg_color = get_x11_color(value);
6438 CONF3("default_outline_color", "default_outlinecolor") {
6440 default_out_color = get_x11_color(value);
6445 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
6446 CONF("xmms_player") {
6448 if (strncmp(value,"none",4)==0)
6449 info.xmms.current_project=PROJECT_NONE;
6450 else if (strncmp(value,"xmms",4)==0)
6451 info.xmms.current_project=PROJECT_XMMS;
6452 else if (strncmp(value,"bmp",3)==0)
6453 info.xmms.current_project=PROJECT_BMP;
6454 else if (strncmp(value,"audacious",9)==0)
6455 info.xmms.current_project=PROJECT_AUDACIOUS;
6456 else if (strncmp(value,"infopipe",8)==0)
6457 info.xmms.current_project=PROJECT_INFOPIPE;
6467 info.mail = parse_mail_args(IMAP, value);
6474 info.mail = parse_mail_args(POP3, value);
6482 strncpy(info.mpd.host, value, 127);
6488 info.mpd.port = strtol(value, 0, 0);
6489 if (info.mpd.port < 1
6490 || info.mpd.port > 0xffff)
6494 CONF("mpd_password") {
6496 strncpy(info.mpd.password, value, 127);
6501 CONF("cpu_avg_samples") {
6503 cpu_avg_samples = strtol(value, 0, 0);
6504 if (cpu_avg_samples < 1
6505 || cpu_avg_samples > 14)
6514 CONF("net_avg_samples") {
6516 net_avg_samples = strtol(value, 0, 0);
6517 if (net_avg_samples < 1
6518 || net_avg_samples > 14)
6534 CONF("double_buffer") {
6535 use_xdbe = string_to_bool(value);
6539 CONF("override_utf8_locale") {
6540 utf8_mode = string_to_bool(value);
6543 CONF("draw_borders") {
6544 draw_borders = string_to_bool(value);
6546 CONF("draw_graph_borders") {
6547 draw_graph_borders = string_to_bool(value);
6549 CONF("draw_shades") {
6550 draw_shades = string_to_bool(value);
6552 CONF("draw_outline") {
6553 draw_outline = string_to_bool(value);
6556 CONF("out_to_console") {
6557 out_to_console = string_to_bool(value);
6559 CONF("use_spacer") {
6560 use_spacer = string_to_bool(value);
6565 use_xft = string_to_bool(value);
6569 set_first_font(value);
6574 if (value && font_count >= 0)
6575 fonts[0].font_alpha = atof(value)
6584 if (string_to_bool(value))
6585 ERR("Xft not enabled");
6588 /* xftfont silently ignored when no Xft */
6591 /* xftalpha is silently ignored when no Xft */
6596 set_first_font(value);
6605 gap_x = atoi(value);
6611 gap_y = atoi(value);
6616 CONF("mail_spool") {
6619 variable_substitute(value, buf, 256);
6623 if (current_mail_spool)
6624 free(current_mail_spool);
6625 current_mail_spool = strdup(buf);
6631 CONF("minimum_size") {
6634 (value, "%d %d", &minimum_width,
6635 &minimum_height) != 2)
6638 &minimum_width) != 1)
6643 CONF("maximum_width") {
6645 if (sscanf(value, "%d", &maximum_width) != 1)
6651 CONF("no_buffers") {
6652 no_buffers = string_to_bool(value);
6655 CONF("mldonkey_hostname") {
6657 if (mlconfig.mldonkey_hostname != NULL) {
6658 free(mlconfig.mldonkey_hostname);
6660 mlconfig.mldonkey_hostname = strdup(value);
6665 CONF("mldonkey_port") {
6667 mlconfig.mldonkey_port = atoi(value);
6671 CONF("mldonkey_login") {
6673 if (mlconfig.mldonkey_login != NULL) {
6674 free(mlconfig.mldonkey_login);
6676 mlconfig.mldonkey_login = strdup(value);
6681 CONF("mldonkey_password") {
6683 if (mlconfig.mldonkey_password != NULL) {
6684 free(mlconfig.mldonkey_password);
6686 mlconfig.mldonkey_password = strdup(value);
6692 CONF("pad_percents") {
6693 pad_percents = atoi(value);
6697 CONF("own_window") {
6698 own_window = string_to_bool(value);
6700 CONF("wm_class_name") {
6701 memset(window.wm_class_name,0,sizeof(window.wm_class_name));
6702 strncpy(window.wm_class_name, value, sizeof(window.wm_class_name)-1);
6704 CONF("own_window_transparent") {
6705 set_transparent = string_to_bool(value);
6707 CONF("own_window_colour") {
6709 background_colour = get_x11_color(value);
6711 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
6714 CONF("own_window_hints") {
6716 char *p_hint, *p_save;
6717 char delim[] = ", ";
6719 /* tokenize the value into individual hints */
6720 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
6722 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
6723 if (strncmp(p_hint,"undecorate",10) == 0)
6724 SET_HINT(window.hints,HINT_UNDECORATED);
6725 else if (strncmp(p_hint,"below",5) == 0)
6726 SET_HINT(window.hints,HINT_BELOW);
6727 else if (strncmp(p_hint,"above",5) == 0)
6728 SET_HINT(window.hints,HINT_ABOVE);
6729 else if (strncmp(p_hint,"sticky",6) == 0)
6730 SET_HINT(window.hints,HINT_STICKY);
6731 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
6732 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
6733 else if (strncmp(p_hint,"skip_pager",10) == 0)
6734 SET_HINT(window.hints,HINT_SKIP_PAGER);
6738 p_hint=strtok_r(NULL, delim, &p_save);
6740 while (p_hint!=NULL);
6743 CONF("own_window_type") {
6745 if (strncmp(value,"normal",6)==0)
6746 window.type = TYPE_NORMAL;
6747 else if (strncmp(value,"desktop",7)==0)
6748 window.type = TYPE_DESKTOP;
6749 else if (strncmp(value,"override",8)==0)
6750 window.type = TYPE_OVERRIDE;
6756 CONF("stippled_borders") {
6758 stippled_borders = strtol(value, 0, 0);
6760 stippled_borders = 4;
6764 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
6767 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
6769 CONF("update_interval") {
6771 update_interval = strtod(value, 0);
6775 CONF("total_run_times") {
6777 total_run_times = strtod(value, 0);
6782 stuff_in_upper_case = string_to_bool(value);
6787 malloc(strlen(value)
6789 strcpy(seti_dir, value);
6793 if (text != original_text)
6803 int l = strlen(text);
6804 if (fgets(buf, 256, fp) == NULL)
6807 realloc(text, l + strlen(buf)
6811 if (strlen(text) > 1024 * 8)
6815 text_lines = line + 1;
6818 #ifdef TCP_PORT_MONITOR
6819 CONF("min_port_monitors")
6822 (sscanf(value, "%d", &tcp_port_monitor_collection_args.min_port_monitors) != 1) ||
6823 tcp_port_monitor_collection_args.min_port_monitors < 0 )
6825 /* an error. use default, warn and continue. */
6826 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6829 else if ( tcp_port_monitor_collection_args.min_port_monitors == 0 )
6831 /* no error, just use default */
6832 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6834 /* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
6836 CONF("min_port_monitor_connections")
6839 (sscanf(value, "%d", &tcp_port_monitor_args.min_port_monitor_connections) != 1)
6840 || tcp_port_monitor_args.min_port_monitor_connections < 0 )
6842 /* an error. use default, warni and continue. */
6843 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6846 else if ( tcp_port_monitor_args.min_port_monitor_connections == 0 )
6848 /* no error, just use default */
6849 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6851 /* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
6855 ERR("%s: %d: no such configuration: '%s'", f, line, name);
6867 /* : means that character before that takes an argument */
6868 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
6881 int main(int argc, char **argv)
6883 struct sigaction act, oact;
6886 memset(&info, 0, sizeof(info) );
6888 #ifdef TCP_PORT_MONITOR
6889 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6890 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6894 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_XMMS);
6897 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_BMP);
6899 #if defined(AUDACIOUS)
6900 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_AUDACIOUS);
6902 #if defined(INFOPIPE)
6903 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_INFOPIPE);
6906 /* handle command line parameters that don't change configs */
6912 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
6913 *s) || ((s = getenv("LANG")) && *s)) {
6915 for(x = 0; x < strlen(s) ; x++) {
6916 temp[x] = tolower(s[x]);
6918 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
6922 if (!setlocale(LC_CTYPE, "")) {
6923 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
6927 int c = getopt(argc,
6938 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
6939 * though free() does the NULL check itself;), then load optarg value */
6941 free(current_config);
6942 current_config = strdup(optarg);
6947 ("Usage: %s [OPTION]...\n"
6948 "Conky is a system monitor that renders text on desktop or to own transparent\n"
6949 "window. Command line options will override configurations defined in config\n"
6952 " -c FILE config file to load instead of "
6955 " -d daemonize, fork to background\n"
6958 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
6959 " -f FONT font to use\n"
6961 " -o create own window to draw\n"
6964 " -b double buffer (prevents flickering)\n"
6966 " -w WIN_ID window id to draw\n"
6967 " -x X x position\n"
6968 " -y Y y position\n"
6970 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
6971 " -u SECS update interval\n"
6972 " -i NUM number of times to update Conky\n", argv[0]);
6976 window.window = strtol(optarg, 0, 0);
6985 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
6989 /* load current_config or CONFIG_FILE */
6992 if (current_config == NULL) {
6993 /* load default config file */
6996 variable_substitute(CONFIG_FILE, buf, 256);
6999 current_config = strdup(buf);
7003 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7004 load_config_file(current_config);
7006 set_default_configurations();
7010 if (current_mail_spool == NULL) {
7012 variable_substitute(MAIL_FILE, buf, 256);
7015 current_mail_spool = strdup(buf);
7019 /* handle other command line arguments */
7021 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7022 optind = optreset = 1;
7027 #if defined(__FreeBSD__)
7028 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7029 O_RDONLY, "kvm_open")) == NULL)
7030 CRIT_ERR( "cannot read kvm");
7034 int c = getopt(argc,
7042 fork_to_background = 1;
7047 set_first_font(optarg);
7050 text_alignment = string_to_alignment(optarg);
7065 if (text != original_text)
7067 text = strdup(optarg);
7068 convert_escapes(text);
7072 update_interval = strtod(optarg, 0);
7076 total_run_times = strtod(optarg, 0);
7080 gap_x = atoi(optarg);
7084 gap_y = atoi(optarg);
7098 /* generate text and get initial size */
7099 extract_variable_text(text);
7100 if (text != original_text) {
7105 if (fork_to_background) {
7109 ERR("can't fork() to background: %s",
7116 fprintf(stderr,"\n");fflush(stderr);
7120 /* parent process */
7121 fprintf(stderr,"Conky: forked to background, pid is %d\n",pid);
7132 update_text_area(); /* to get initial size of the window */
7136 text_width + border_margin * 2 + 1,
7137 text_height + border_margin * 2 + 1,
7138 set_transparent, background_colour, info.uname_s.nodename, argv, argc);
7141 update_text_area(); /* to position text/window on screen */
7145 // why the fuck not?
7151 if (own_window && !fixed_pos) {
7152 XMoveWindow(display, window.window, window.x, window.y);
7155 set_transparent_background(window.window);
7166 /* Set signal handlers */
7167 act.sa_handler = signal_handler;
7168 sigemptyset(&act.sa_mask);
7171 act.sa_flags |= SA_RESTART;
7174 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7175 sigaction(SIGUSR1,&act,&oact) < 0 ||
7176 sigaction(SIGTERM,&act,&oact) < 0 )
7178 ERR("error setting signal handler: %s", strerror(errno) );
7181 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
7182 if ( (info.xmms.current_project > PROJECT_NONE) && (create_xmms_thread() !=0) )
7184 CRIT_ERR("unable to create xmms_player thread!");
7190 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
7191 if ( info.xmms.thread && (destroy_xmms_thread()!=0) )
7193 ERR("error destroying xmms_player thread");
7197 #if defined(__FreeBSD__)
7204 void signal_handler(int sig)
7206 /* signal handler is light as a feather, as it should be.
7207 * we will poll g_signal_pending with each loop of conky
7208 * and do any signal processing there, NOT here. pkovacs. */
7209 g_signal_pending=sig;