2 * Conky, a system monitor, based on torsmo
4 * Any original torsmo code is licensed under the BSD license
6 * All code written since the fork of torsmo is licensed under the GPL
8 * Please see COPYING for details
10 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
46 #include <X11/Xutil.h>
48 #include <X11/extensions/Xdamage.h>
54 #include <sys/types.h>
56 #include <netinet/in.h>
67 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
70 #define CONFIG_FILE "$HOME/.conkyrc"
71 #define MAIL_FILE "$MAIL"
72 #define MAX_IF_BLOCK_DEPTH 5
74 /* #define SIGNAL_BLOCKING */
75 #undef SIGNAL_BLOCKING
77 static void print_version()
79 printf("Conky %s compiled %s for %s\n",
80 VERSION, BUILD_DATE, BUILD_ARCH);
83 "\nCompiled in features:\n\n"
87 " * Xdamage extension\n"
88 # endif /* HAVE_XDAMAGE */
90 " * Xdbe extension (double buffer)\n"
91 # endif /* HAVE_XDBE */
97 "\n Music detection:\n"
100 #endif /* AUDACIOUS */
110 "\n General features:\n"
114 #ifdef TCP_PORT_MONITOR
116 #endif /* TCP_PORT_MONITOR */
134 static int text_start_x, text_start_y; /* text start position in window */
135 static int text_width, text_height;
150 char name[TEXT_BUFFER_SIZE];
160 static int selected_font = 0;
161 static int font_count = -1;
162 struct font_list *fonts = NULL;
166 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
167 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
168 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
169 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
173 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
174 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
175 #define font_descent() fonts[selected_font].font->max_bounds.descent
179 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
182 static void set_font();
184 int addfont(const char *data_in)
186 if (font_count > MAX_FONTS) {
187 CRIT_ERR("you don't need that many fonts, sorry.");
190 if (font_count == 0) {
194 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
198 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
200 CRIT_ERR("realloc in addfont");
202 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
203 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
205 fonts[font_count].font_alpha = 0xffff;
208 CRIT_ERR("Oops...looks like something overflowed in addfont().");
213 void set_first_font(const char *data_in)
215 if (font_count < 0) {
216 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
221 if (strlen(data_in) > 1) {
222 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
224 fonts[0].font_alpha = 0xffff;
232 for (i = 0; i <= font_count; i++) {
235 XftFontClose(display, fonts[i].xftfont);
239 XFreeFont(display, fonts[i].font);
249 static void load_fonts()
252 for (i=0; i <= font_count; i++) {
256 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
257 XftFontClose(display, fonts[i].xftfont);
259 if ((fonts[i].xftfont =
260 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
263 ERR("can't load Xft font '%s'", fonts[i].name);
264 if ((fonts[i].xftfont =
265 XftFontOpenName(display, screen,
266 "courier-12")) != NULL)
269 ERR("can't load Xft font '%s'", "courier-12");
271 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
272 CRIT_ERR("can't load font '%s'", "fixed");
279 /* load normal font */
280 /* if (fonts[i].font != NULL)
281 XFreeFont(display, fonts[i].font);*/
283 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
284 ERR("can't load font '%s'", fonts[i].name);
285 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
286 CRIT_ERR("can't load font '%s'", "fixed");
287 printf("loaded fixed?\n");
295 /* default config file */
296 static char *current_config;
298 /* set to 1 if you want all text to be in uppercase */
299 static unsigned int stuff_in_upper_case;
301 /* Run how many times? */
302 static unsigned long total_run_times;
305 static int fork_to_background;
307 static int cpu_avg_samples, net_avg_samples;
311 /* Position on the screen */
312 static int text_alignment;
313 static int gap_x, gap_y;
316 static int draw_borders;
317 static int draw_graph_borders;
318 static int stippled_borders;
320 static int draw_shades, draw_outline;
322 static int border_margin, border_width;
324 static long default_fg_color, default_bg_color, default_out_color;
326 /* create own window or draw stuff to root? */
327 static int set_transparent = 0;
331 static int own_window = 0;
332 static int background_colour = 0;
333 /* fixed size/pos is set if wm/user changes them */
334 static int fixed_size = 0, fixed_pos = 0;
337 static int minimum_width, minimum_height;
338 static int maximum_width;
343 static int sensor_device;
346 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
348 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
349 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
351 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
352 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
354 /* maximum size of individual text buffers, ie $exec buffer size */
355 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
358 #define CODEPAGE_LENGTH 20
360 long iconv_count = 0;
361 char iconv_converting;
362 static iconv_t **iconv_cd = 0;
364 int register_iconv(iconv_t *new_iconv)
367 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
369 iconv_cd = malloc(sizeof(iconv_t *));
372 CRIT_ERR("Out of memory");
374 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
375 if (!iconv_cd[iconv_count]) {
376 CRIT_ERR("Out of memory");
378 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
383 void free_iconv(void)
387 for (i = 0; i < iconv_count; i++) {
389 iconv_close(*iconv_cd[i]);
404 /* no buffers in used memory? */
407 /* pad percentages to decimals? */
408 static int pad_percents = 0;
410 #ifdef TCP_PORT_MONITOR
411 tcp_port_monitor_args_t tcp_port_monitor_args;
414 /* Text that is shown */
415 static char original_text[] =
416 "$nodename - $sysname $kernel on $machine\n"
418 "${color grey}Uptime:$color $uptime\n"
419 "${color grey}Frequency (in MHz):$color $freq\n"
420 "${color grey}Frequency (in GHz):$color $freq_g\n"
421 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
422 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
423 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
424 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
426 "${color grey}File systems:\n"
427 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
428 "${color grey}Networking:\n"
429 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
432 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
433 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
436 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
437 "Progress: $xmms2_bar\n"
439 "${color grey}Name PID CPU% MEM%\n"
440 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
441 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
442 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
443 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
446 static char *text = original_text;
449 static int total_updates;
452 static int blockdepth = 0;
453 static int if_jumped = 0;
454 static int blockstart[MAX_IF_BLOCK_DEPTH];
456 int check_contains(char *f, char *s)
459 FILE *where = fopen(f, "r");
461 char buf1[256], buf2[256];
462 while (fgets(buf1, 256, where)) {
463 sscanf(buf1, "%255s", buf2);
464 if (strstr(buf2, s)) {
471 ERR("Could not open the file");
478 static inline int calc_text_width(const char *s, int l)
484 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
486 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
492 return XTextWidth(fonts[selected_font].font, s, l);
497 /* formatted text to render on screen, generated in generate_text(),
498 * drawn in draw_stuff() */
500 static char text_buffer[TEXT_BUFFER_SIZE * 4];
502 /* special stuff in text_buffer */
504 #define SPECIAL_CHAR '\x01'
532 unsigned long first_colour; // for graph gradient
533 unsigned long last_colour;
537 /* create specials array on heap instead of stack with introduction of max_specials */
538 static struct special_t *specials = NULL;
540 static unsigned int special_count;
542 static unsigned int special_index; /* used when drawing */
545 #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? */
547 static struct special_t *new_special(char *buf, int t)
549 if (special_count >= max_specials)
550 CRIT_ERR("too many special things in text");
552 buf[0] = SPECIAL_CHAR;
554 specials[special_count].type = t;
555 return &specials[special_count++];
558 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
561 unsigned int count = 0;
562 static char buf[BUFSZ];
563 long orig_pos = ftell(fp);
565 long buf_size = BUFSZ;
566 char* cur_found = NULL;
567 while(count < step) {
568 if(cur_found == NULL) {
569 buf_size = fread(buf, 1, buf_size, fp);
572 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
573 if(cur_found != NULL) {
574 buf_pos = cur_found-buf+1;
583 ret = ftell(fp) - buf_size + buf_pos - 1;
584 fseek(fp, orig_pos, SEEK_SET);
591 memrchr (const void *buffer, int c, size_t n)
593 const unsigned char *p = buffer;
595 for (p += n; n ; n--)
601 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
604 unsigned int count = 0;
605 static char buf[BUFSZ];
606 long orig_pos = ftell(fp);
608 long file_pos = orig_pos;
609 long buf_size = BUFSZ;
611 while(count < step) {
613 if(file_pos > BUFSZ) {
614 fseek(fp, file_pos-BUFSZ, SEEK_SET);
618 fseek(fp, 0, SEEK_SET);
620 file_pos = ftell(fp);
621 buf_pos = fread(buf, 1, buf_size, fp);
628 if(cur_found != NULL) {
629 buf_pos = cur_found-buf;
638 fseek(fp, orig_pos, SEEK_SET);
640 ret = file_pos + buf_pos;
645 static void new_bar(char *buf, int w, int h, int usage)
647 struct special_t *s = new_special(buf, BAR);
648 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
653 static const char *scan_bar(const char *args, int *w, int *h)
655 *w = 0; /* zero width means all space that is available */
657 /* bar's argument is either height or height,width */
660 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
661 sscanf(args, "%d %n", h, &n);
668 static char *scan_font(const char *args)
677 static void new_font(char *buf, char * args) {
679 struct special_t *s = new_special(buf, FONT);
680 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
681 int tmp = selected_font;
682 selected_font = s->font_added = addfont(args);
687 struct special_t *s = new_special(buf, FONT);
688 int tmp = selected_font;
689 selected_font = s->font_added = 0;
695 inline void graph_append(struct special_t *graph, double f)
697 if (!graph->scaled && f > graph->graph_scale) {
698 f = graph->graph_scale;
702 graph->graph_scale = 1;
704 graph->graph[0] = f; /* add new data */
705 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
706 graph->graph[i] = graph->graph[i - 1];
707 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
708 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
713 short colour_depth = 0;
714 void set_up_gradient();
716 /* precalculated: 31/255, and 63/255 */
717 #define CONST_8_TO_5_BITS 0.12156862745098
718 #define CONST_8_TO_6_BITS 0.247058823529412
720 /* adjust color values depending on color depth*/
721 static unsigned int adjust_colors(unsigned int color)
724 if (colour_depth == 0) {
727 if (colour_depth == 16) {
728 r = (color & 0xff0000) >> 16;
729 g = (color & 0xff00) >> 8;
731 color = (int)(r * CONST_8_TO_5_BITS) << 11;
732 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
733 color |= (int)(b * CONST_8_TO_5_BITS);
738 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
740 struct special_t *s = new_special(buf, GRAPH);
742 if (s->graph == NULL) {
743 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
744 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
746 s->graph_width = MAX_GRAPH_DEPTH - 2;
748 s->graph = malloc(s->graph_width * sizeof(double));
749 memset(s->graph, 0, s->graph_width * sizeof(double));
750 s->graph_scale = 100;
753 s->first_colour = adjust_colors(first_colour);
754 s->last_colour = adjust_colors(second_colour);
761 s->graph_width = s->width - 2; // subtract 2 for rectangle around
766 s->graph_scale = scale;
773 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
775 *w = 0; /* zero width means all space that is available */
779 /* graph's argument is either height or height,width */
781 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
782 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
784 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
786 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
789 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
793 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
796 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
800 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
803 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
807 if (sscanf(args, "%d,%d", h, w) < 2) {
810 sscanf(args, "%*s %d,%d", h, w);
816 static inline void new_hr(char *buf, int a)
818 new_special(buf, HORIZONTAL_LINE)->height = a;
821 static inline void new_stippled_hr(char *buf, int a, int b)
823 struct special_t *s = new_special(buf, STIPPLED_HR);
828 static inline void new_fg(char *buf, long c)
830 new_special(buf, FG)->arg = c;
833 static inline void new_bg(char *buf, long c)
835 new_special(buf, BG)->arg = c;
838 static inline void new_outline(char *buf, long c)
840 new_special(buf, OUTLINE)->arg = c;
843 static inline void new_offset(char *buf, long c)
845 new_special(buf, OFFSET)->arg = c;
848 static inline void new_voffset(char *buf, long c)
850 new_special(buf, VOFFSET)->arg = c;
853 static inline void new_alignr(char *buf, long c)
855 new_special(buf, ALIGNR)->arg = c;
858 static inline void new_alignc(char *buf, long c)
860 new_special(buf, ALIGNC)->arg = c;
863 static inline void new_goto(char *buf, long c)
865 new_special(buf, GOTO)->arg = c;
868 static inline void new_tab(char *buf, int a, int b) {
869 struct special_t *s = new_special(buf, TAB);
874 /* quite boring functions */
876 static inline void for_each_line(char *b, void (*f) (char *))
880 for (ps = b, pe = b; *pe; pe++) {
893 static void convert_escapes(char *buf)
895 char *p = buf, *s = buf;
911 /* converts from bytes to human readable format (k, M, G, T) */
912 static void human_readable(long long a, char *buf, int size)
914 // Strange conditional due to possible overflows
915 if(a / 1024 / 1024 / 1024.0 > 1024.0){
916 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
918 else if (a >= 1024 * 1024 * 1024) {
919 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
921 else if (a >= 1024 * 1024) {
922 double m = (a / 1024) / 1024.0;
924 snprintf(buf, size, "%.0fMiB", m);
926 snprintf(buf, size, "%.1fMiB", m);
927 } else if (a >= 1024)
928 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
930 snprintf(buf, size, "%LdB", a);
935 enum text_object_type {
948 #endif /* !__OpenBSD__ */
970 OBJ_diskiograph_read,
971 OBJ_diskiograph_write,
1006 #if defined(__linux__)
1012 OBJ_i8k_left_fan_status,
1013 OBJ_i8k_right_fan_status,
1014 OBJ_i8k_left_fan_rpm,
1015 OBJ_i8k_right_fan_rpm,
1017 OBJ_i8k_buttons_status,
1027 OBJ_wireless_bitrate,
1029 OBJ_wireless_link_qual,
1030 OBJ_wireless_link_qual_max,
1031 OBJ_wireless_link_qual_perc,
1032 OBJ_wireless_link_bar,
1033 #endif /* __linux__ */
1062 OBJ_running_processes,
1071 OBJ_temp1, /* i2c is used instead in these */
1091 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1093 OBJ_apm_battery_time,
1094 OBJ_apm_battery_life,
1095 #endif /* __FreeBSD__ __OpenBSD__ */
1097 OBJ_obsd_sensors_temp,
1098 OBJ_obsd_sensors_fan,
1099 OBJ_obsd_sensors_volt,
1102 #endif /* __OpenBSD__ */
1124 OBJ_music_player_interval,
1132 OBJ_xmms2_transport,
1147 OBJ_audacious_status,
1148 OBJ_audacious_title,
1149 OBJ_audacious_length,
1150 OBJ_audacious_length_seconds,
1151 OBJ_audacious_position,
1152 OBJ_audacious_position_seconds,
1153 OBJ_audacious_bitrate,
1154 OBJ_audacious_frequency,
1155 OBJ_audacious_channels,
1156 OBJ_audacious_filename,
1157 OBJ_audacious_playlist_length,
1158 OBJ_audacious_playlist_position,
1172 #ifdef TCP_PORT_MONITOR
1183 OBJ_entropy_poolsize,
1187 struct text_object {
1189 char *s; /* some string */
1190 int i; /* some integer */
1191 long l; /* some other integer */
1192 unsigned int sensor;
1193 struct net_stat *net;
1195 unsigned char loadavg[3];
1196 unsigned int cpu_index;
1197 struct mail_s *mail;
1205 char *tz; /* timezone variable */
1206 char *fmt; /* time display formatting */
1244 /* If not -1, a file descriptor to read from when
1245 * logfile is a FIFO. */
1262 timed_thread *p_timed_thread;
1268 #ifdef TCP_PORT_MONITOR
1270 in_port_t port_range_begin; /* starting port to monitor */
1271 in_port_t port_range_end; /* ending port to monitor */
1272 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1273 int connection_index; /* 0 to n-1 connections. */
1291 struct local_mail_s local_mail;
1296 unsigned int c, d, e;
1301 struct text_object_list {
1302 unsigned int text_object_count;
1303 struct text_object *text_objects;
1306 static unsigned int text_object_count;
1307 static struct text_object *text_objects;
1308 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1310 #define MAXDATASIZE 1000
1314 struct mail_s* parse_mail_args(char type, const char *arg) {
1315 struct mail_s *mail;
1316 mail = malloc(sizeof(struct mail_s));
1317 memset(mail, 0, sizeof(struct mail_s));
1319 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1321 ERR("Scanning IMAP args failed");
1322 } else if (type == IMAP) {
1323 ERR("Scanning POP3 args failed");
1326 // see if password needs prompting
1327 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1328 int fp = fileno(stdin);
1329 struct termios term;
1330 tcgetattr(fp, &term);
1331 term.c_lflag &= ~ECHO;
1332 tcsetattr(fp, TCSANOW, &term);
1333 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1334 scanf("%128s", mail->pass);
1336 term.c_lflag |= ECHO;
1337 tcsetattr(fp, TCSANOW, &term);
1339 // now we check for optional args
1340 tmp = strstr(arg, "-i ");
1343 sscanf(tmp, "%f", &mail->interval);
1345 mail->interval = 300; // 5 minutes
1347 tmp = strstr(arg, "-p ");
1350 sscanf(tmp, "%lu", &mail->port);
1353 mail->port = 110; // default pop3 port
1354 } else if (type == IMAP) {
1355 mail->port = 143; // default imap port
1359 tmp = strstr(arg, "-f ");
1362 sscanf(tmp, "%s", mail->folder);
1364 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1367 tmp = strstr(arg, "-e ");
1371 if (tmp[0] == '\'') {
1372 len = strstr(tmp+1, "'") - tmp - 1;
1377 strncpy(mail->command, tmp+1, len);
1379 mail->command[0] = '\0';
1381 mail->p_timed_thread = NULL;
1385 void *imap_thread(struct mail_s* mail)
1387 int sockfd, numbytes;
1388 char recvbuf[MAXDATASIZE];
1389 char sendbuf[MAXDATASIZE];
1392 unsigned int old_unseen = UINT_MAX;
1393 unsigned int old_messages = UINT_MAX;
1394 struct stat stat_buf;
1396 struct sockaddr_in their_addr; // connector's address information
1397 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1398 herror("gethostbyname");
1403 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1405 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1408 goto next_iteration;
1411 their_addr.sin_family = AF_INET; // host byte order
1412 their_addr.sin_port = htons(mail->port); // short, network byte order
1413 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1414 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1417 (sockfd, (struct sockaddr *) &their_addr,
1418 sizeof(struct sockaddr)) == -1) {
1421 goto next_iteration;
1423 struct timeval timeout;
1426 timeout.tv_sec = 60; // 60 second timeout i guess
1427 timeout.tv_usec = 0;
1429 FD_SET(sockfd, &fdset);
1430 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1433 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1437 goto next_iteration;
1440 ERR("IMAP connection failed: timeout");
1442 goto next_iteration;
1444 recvbuf[numbytes] = '\0';
1445 if (strstr(recvbuf, "* OK") != recvbuf) {
1446 ERR("IMAP connection failed, probably not an IMAP server");
1448 goto next_iteration;
1450 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1451 strncat(sendbuf, mail->user,
1452 MAXDATASIZE - strlen(sendbuf) - 1);
1453 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1454 strncat(sendbuf, mail->pass,
1455 MAXDATASIZE - strlen(sendbuf) - 1);
1456 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1457 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1460 goto next_iteration;
1462 timeout.tv_sec = 60; // 60 second timeout i guess
1463 timeout.tv_usec = 0;
1465 FD_SET(sockfd, &fdset);
1466 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1469 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1473 goto next_iteration;
1476 recvbuf[numbytes] = '\0';
1477 if (strstr(recvbuf, "a1 OK") == NULL) {
1478 ERR("IMAP server login failed: %s", recvbuf);
1480 goto next_iteration;
1482 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1483 strncat(sendbuf, mail->folder,
1484 MAXDATASIZE - strlen(sendbuf) - 1);
1485 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1486 MAXDATASIZE - strlen(sendbuf) - 1);
1487 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1490 goto next_iteration;
1492 timeout.tv_sec = 60; // 60 second timeout i guess
1493 timeout.tv_usec = 0;
1495 FD_SET(sockfd, &fdset);
1496 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1499 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1503 goto next_iteration;
1506 recvbuf[numbytes] = '\0';
1507 if (strstr(recvbuf, "a2 OK") == NULL) {
1508 ERR("IMAP status failed: %s", recvbuf);
1510 goto next_iteration;
1512 // now we get the data
1513 reply = strstr(recvbuf, " (MESSAGES ");
1515 *strchr(reply, ')') = '\0';
1516 if (reply == NULL) {
1517 ERR("Error parsing IMAP response: %s", recvbuf);
1519 goto next_iteration;
1521 timed_thread_lock (mail->p_timed_thread);
1522 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1525 timed_thread_unlock (mail->p_timed_thread);
1527 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1528 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1531 goto next_iteration;
1533 timeout.tv_sec = 60; // 60 second timeout i guess
1534 timeout.tv_usec = 0;
1536 FD_SET(sockfd, &fdset);
1537 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1540 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1544 goto next_iteration;
1547 recvbuf[numbytes] = '\0';
1548 if (strstr(recvbuf, "a3 OK") == NULL) {
1549 ERR("IMAP logout failed: %s", recvbuf);
1551 goto next_iteration;
1553 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1554 if (system(mail->command) == -1) {
1559 old_unseen = mail->unseen;
1560 old_messages = mail->messages;
1562 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1563 /* if a valid socket, close it */
1565 if (timed_thread_test (mail->p_timed_thread))
1566 timed_thread_exit (mail->p_timed_thread);
1573 void *pop3_thread(struct mail_s *mail)
1575 int sockfd, numbytes;
1576 char recvbuf[MAXDATASIZE];
1577 char sendbuf[MAXDATASIZE];
1580 unsigned int old_unseen = UINT_MAX;
1581 struct stat stat_buf;
1583 struct sockaddr_in their_addr; // connector's address information
1584 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1585 herror("gethostbyname");
1590 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1592 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1595 goto next_iteration;
1598 their_addr.sin_family = AF_INET; // host byte order
1599 their_addr.sin_port = htons(mail->port); // short, network byte order
1600 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1601 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1604 (sockfd, (struct sockaddr *) &their_addr,
1605 sizeof(struct sockaddr)) == -1) {
1608 goto next_iteration;
1610 struct timeval timeout;
1613 timeout.tv_sec = 60; // 60 second timeout i guess
1614 timeout.tv_usec = 0;
1616 FD_SET(sockfd, &fdset);
1617 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1620 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1624 goto next_iteration;
1627 ERR("POP3 connection failed: timeout\n");
1629 goto next_iteration;
1631 recvbuf[numbytes] = '\0';
1632 if (strstr(recvbuf, "+OK ") != recvbuf) {
1633 ERR("POP3 connection failed, probably not a POP3 server");
1635 goto next_iteration;
1637 strncpy(sendbuf, "USER ", MAXDATASIZE);
1638 strncat(sendbuf, mail->user,
1639 MAXDATASIZE - strlen(sendbuf) - 1);
1640 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1641 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1642 perror("send USER");
1644 goto next_iteration;
1646 timeout.tv_sec = 60; // 60 second timeout i guess
1647 timeout.tv_usec = 0;
1649 FD_SET(sockfd, &fdset);
1650 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1653 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1655 perror("recv USER");
1657 goto next_iteration;
1660 recvbuf[numbytes] = '\0';
1661 if (strstr(recvbuf, "+OK ") == NULL) {
1662 ERR("POP3 server login failed: %s", recvbuf);
1664 goto next_iteration;
1666 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1667 strncat(sendbuf, mail->pass,
1668 MAXDATASIZE - strlen(sendbuf) - 1);
1669 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1670 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1671 perror("send PASS");
1673 goto next_iteration;
1675 timeout.tv_sec = 60; // 60 second timeout i guess
1676 timeout.tv_usec = 0;
1678 FD_SET(sockfd, &fdset);
1679 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1682 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1684 perror("recv PASS");
1686 goto next_iteration;
1689 recvbuf[numbytes] = '\0';
1690 if (strstr(recvbuf, "+OK ") == NULL) {
1691 ERR("POP3 server login failed: %s", recvbuf);
1693 goto next_iteration;
1695 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1696 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1697 perror("send STAT");
1699 goto next_iteration;
1701 timeout.tv_sec = 60; // 60 second timeout i guess
1702 timeout.tv_usec = 0;
1704 FD_SET(sockfd, &fdset);
1705 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1708 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1710 perror("recv STAT");
1712 goto next_iteration;
1715 recvbuf[numbytes] = '\0';
1716 if (strstr(recvbuf, "+OK ") == NULL) {
1717 ERR("POP3 status failed: %s", recvbuf);
1719 goto next_iteration;
1721 // now we get the data
1722 reply = recvbuf + 4;
1723 if (reply == NULL) {
1724 ERR("Error parsing POP3 response: %s", recvbuf);
1726 goto next_iteration;
1728 timed_thread_lock (mail->p_timed_thread);
1729 sscanf(reply, "%lu %lu", &mail->unseen,
1731 timed_thread_unlock (mail->p_timed_thread);
1733 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1734 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1735 perror("send QUIT");
1737 goto next_iteration;
1739 timeout.tv_sec = 60; // 60 second timeout i guess
1740 timeout.tv_usec = 0;
1742 FD_SET(sockfd, &fdset);
1743 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1746 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1748 perror("recv QUIT");
1750 goto next_iteration;
1753 recvbuf[numbytes] = '\0';
1754 if (strstr(recvbuf, "+OK") == NULL) {
1755 ERR("POP3 logout failed: %s", recvbuf);
1757 goto next_iteration;
1759 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1760 if (system(mail->command) == -1) {
1765 old_unseen = mail->unseen;
1767 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1768 /* if a valid socket, close it */
1770 if (timed_thread_test (mail->p_timed_thread))
1771 timed_thread_exit (mail->p_timed_thread);
1779 void *threaded_exec(struct text_object *obj) {
1781 char *p2 = obj->data.texeci.buffer;
1782 FILE *fp = popen(obj->data.texeci.cmd,"r");
1783 timed_thread_lock (obj->data.texeci.p_timed_thread);
1784 int n2 = fread(p2, 1, text_buffer_size, fp);
1787 if (n2 && p2[n2 - 1] == '\n') {
1791 if (*p2 == '\001') {
1796 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1797 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1798 timed_thread_exit (obj->data.texeci.p_timed_thread);
1803 static struct text_object *new_text_object_internal()
1805 struct text_object *obj = malloc(sizeof(struct text_object));
1806 memset(obj, 0, sizeof(struct text_object));
1810 static void free_text_objects(unsigned int count, struct text_object *objs)
1813 for (i = 0; i < count; i++) {
1814 switch (objs[i].type) {
1817 close(objs[i].data.i);
1820 close(objs[i].data.i);
1823 close(objs[i].data.sysfs.fd);
1826 close(objs[i].data.sysfs.fd);
1829 close(objs[i].data.sysfs.fd);
1831 #endif /* !__OpenBSD__ */
1833 free(objs[i].data.s);
1836 free(objs[i].data.s);
1839 free(objs[i].data.tztime.tz);
1840 free(objs[i].data.tztime.fmt);
1843 free(objs[i].data.mboxscan.args);
1844 free(objs[i].data.mboxscan.output);
1848 free(objs[i].data.local_mail.box);
1853 case OBJ_imap_unseen:
1854 if (!objs[i].global_mode) {
1855 free(objs[i].data.mail);
1858 case OBJ_imap_messages:
1859 if (!objs[i].global_mode) {
1860 free(objs[i].data.mail);
1866 case OBJ_pop3_unseen:
1867 if (!objs[i].global_mode) {
1868 free(objs[i].data.mail);
1872 if (!objs[i].global_mode) {
1873 free(objs[i].data.mail);
1877 case OBJ_if_existing:
1878 case OBJ_if_mounted:
1879 case OBJ_if_running:
1880 free(objs[i].data.ifblock.s);
1881 free(objs[i].data.ifblock.str);
1884 free(objs[i].data.tail.logfile);
1885 free(objs[i].data.tail.buffer);
1889 free(objs[i].data.s);
1892 free(objs[i].data.s);
1895 free(objs[i].data.s);
1898 free(objs[i].data.s);
1901 free(objs[i].data.s);
1903 /* case OBJ_execibar:
1904 free(objs[i].data.s);
1906 case OBJ_execigraph:
1907 free(objs[i].data.s);
1910 case OBJ_iconv_start:
1915 case OBJ_xmms2_artist:
1916 if (info.xmms2.artist) {
1917 free(info.xmms2.artist);
1918 info.xmms2.artist = 0;
1921 case OBJ_xmms2_album:
1922 if (info.xmms2.album) {
1923 free(info.xmms2.album);
1924 info.xmms2.album = 0;
1927 case OBJ_xmms2_title:
1928 if (info.xmms2.title) {
1929 free(info.xmms2.title);
1930 info.xmms2.title = 0;
1933 case OBJ_xmms2_genre:
1934 if (info.xmms2.genre) {
1935 free(info.xmms2.genre);
1936 info.xmms2.genre = 0;
1939 case OBJ_xmms2_comment:
1940 if (info.xmms2.comment) {
1941 free(info.xmms2.comment);
1942 info.xmms2.comment = 0;
1945 case OBJ_xmms2_decoder:
1946 if (info.xmms2.decoder) {
1947 free(info.xmms2.decoder);
1951 case OBJ_xmms2_transport:
1952 if (info.xmms2.transport) {
1953 free(info.xmms2.transport);
1958 if (info.xmms2.url) {
1959 free(info.xmms2.url);
1963 case OBJ_xmms2_date:
1964 if (info.xmms2.date) {
1965 free(info.xmms2.date);
1966 info.xmms2.date = 0;
1969 case OBJ_xmms2_status:
1970 if (info.xmms2.status) {
1971 free(info.xmms2.status);
1972 info.xmms2.status = 0;
1975 case OBJ_xmms2_smart:
1976 if (info.xmms2.artist) {
1977 free(info.xmms2.artist);
1978 info.xmms2.artist = 0;
1980 if (info.xmms2.title) {
1981 free(info.xmms2.title);
1982 info.xmms2.title = 0;
1984 if (info.xmms2.url) {
1985 free(info.xmms2.url);
1991 case OBJ_bmpx_title:
1992 case OBJ_bmpx_artist:
1993 case OBJ_bmpx_album:
1994 case OBJ_bmpx_track:
1996 case OBJ_bmpx_bitrate:
2000 free(objs[i].data.rss.uri);
2001 free(objs[i].data.rss.action);
2007 free(objs[i].data.s);
2009 case OBJ_battery_time:
2010 free(objs[i].data.s);
2012 #endif /* !__OpenBSD__ */
2014 free(objs[i].data.execi.cmd);
2015 free(objs[i].data.execi.buffer);
2018 free(objs[i].data.texeci.cmd);
2019 free(objs[i].data.texeci.buffer);
2022 if (info.first_process) {
2023 free_all_processes();
2024 info.first_process = NULL;
2028 if (info.first_process) {
2029 free_all_processes();
2030 info.first_process = NULL;
2035 free(objs[i].data.hddtemp.dev);
2036 free(objs[i].data.hddtemp.addr);
2039 case OBJ_entropy_avail:
2040 case OBJ_entropy_poolsize:
2041 case OBJ_entropy_bar:
2048 if (info.mpd.title) {
2049 free(info.mpd.title);
2052 if (info.mpd.artist) {
2053 free(info.mpd.artist);
2054 info.mpd.artist = 0;
2056 if (info.mpd.album) {
2057 free(info.mpd.album);
2060 if (info.mpd.random) {
2061 free(info.mpd.random);
2062 info.mpd.random = 0;
2064 if (info.mpd.repeat) {
2065 free(info.mpd.repeat);
2066 info.mpd.repeat = 0;
2068 if (info.mpd.track) {
2069 free(info.mpd.track);
2072 if (info.mpd.name) {
2073 free(info.mpd.name);
2076 if (info.mpd.file) {
2077 free(info.mpd.file);
2080 if (info.mpd.status) {
2081 free(info.mpd.status);
2082 info.mpd.status = 0;
2086 //text_objects = NULL;
2087 //text_object_count = 0;
2090 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2095 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2096 *a = mixer_init(buf1);
2097 (void) scan_bar(arg + n, w, h);
2100 (void) scan_bar(arg, w, h);
2105 /* construct_text_object() creates a new text_object */
2106 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2108 //struct text_object *obj = new_text_object();
2109 struct text_object *obj = new_text_object_internal();
2112 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2113 #define END ; } } else
2117 obj->type = OBJ_color;
2118 obj->data.l = get_x11_color(s);
2122 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2123 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2124 END OBJ(acpiacadapter, 0)
2125 #endif /* !__OpenBSD__ */
2127 OBJ(freq, INFO_FREQ)
2129 END OBJ(freq, INFO_FREQ)
2136 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2138 obj->data.cpu_index=1;
2139 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2143 obj->data.cpu_index=atoi(&arg[0]);
2146 END OBJ(freq_g, INFO_FREQ)
2152 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2154 obj->data.cpu_index=1;
2155 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2159 obj->data.cpu_index=atoi(&arg[0]);
2162 #if defined(__linux__)
2163 END OBJ(voltage_mv, 0)
2169 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2171 obj->data.cpu_index=1;
2172 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2176 obj->data.cpu_index=atoi(&arg[0]);
2179 END OBJ(voltage_v, 0)
2185 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2187 obj->data.cpu_index=1;
2188 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2192 obj->data.cpu_index=atoi(&arg[0]);
2197 END OBJ(wireless_essid, INFO_NET)
2199 obj->data.net = get_net_stat(arg);
2201 CRIT_ERR("wireless_essid: needs an argument");
2202 END OBJ(wireless_mode, INFO_NET)
2204 obj->data.net = get_net_stat(arg);
2206 CRIT_ERR("wireless_mode: needs an argument");
2207 END OBJ(wireless_bitrate, INFO_NET)
2209 obj->data.net = get_net_stat(arg);
2211 CRIT_ERR("wireless_bitrate: needs an argument");
2212 END OBJ(wireless_ap, INFO_NET)
2214 obj->data.net = get_net_stat(arg);
2216 CRIT_ERR("wireless_ap: needs an argument");
2217 END OBJ(wireless_link_qual, INFO_NET)
2219 obj->data.net = get_net_stat(arg);
2221 CRIT_ERR("wireless_link_qual: needs an argument");
2222 END OBJ(wireless_link_qual_max, INFO_NET)
2224 obj->data.net = get_net_stat(arg);
2226 CRIT_ERR("wireless_link_qual_max: needs an argument");
2227 END OBJ(wireless_link_qual_perc, INFO_NET)
2229 obj->data.net = get_net_stat(arg);
2231 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2232 END OBJ(wireless_link_bar, INFO_NET)
2234 arg = scan_bar(arg, &obj->a, &obj->b);
2235 obj->data.net = get_net_stat(arg);
2237 CRIT_ERR("wireless_link_bar: needs an argument");
2238 #endif /* HAVE_IWLIB */
2240 #endif /* __linux__ */
2241 END OBJ(freq_dyn, 0);
2242 END OBJ(freq_dyn_g, 0);
2244 END OBJ(acpifan, 0);
2245 END OBJ(battery, 0);
2248 sscanf(arg, "%63s", bat);
2250 strcpy(bat, "BAT0");
2251 obj->data.s = strdup(bat);
2252 END OBJ(battery_time, 0);
2255 sscanf(arg, "%63s", bat);
2257 strcpy(bat, "BAT0");
2258 obj->data.s = strdup(bat);
2259 END OBJ(battery_percent, 0);
2262 sscanf(arg, "%63s", bat);
2264 strcpy(bat, "BAT0");
2265 obj->data.s = strdup(bat);
2266 END OBJ(battery_bar, 0);
2269 arg = scan_bar(arg, &obj->a, &obj->b);
2270 sscanf(arg, "%63s", bat);
2272 strcpy(bat, "BAT0");
2274 obj->data.s = strdup(bat);
2275 #endif /* !__OpenBSD__ */
2276 #if defined(__linux__)
2277 END OBJ(i8k_version, INFO_I8K)
2278 END OBJ(i8k_bios, INFO_I8K)
2279 END OBJ(i8k_serial, INFO_I8K)
2280 END OBJ(i8k_cpu_temp, INFO_I8K)
2281 END OBJ(i8k_cpu_tempf, INFO_I8K)
2282 END OBJ(i8k_left_fan_status, INFO_I8K)
2283 END OBJ(i8k_right_fan_status, INFO_I8K)
2284 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2285 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2286 END OBJ(i8k_ac_status, INFO_I8K)
2287 END OBJ(i8k_buttons_status, INFO_I8K)
2289 END OBJ(ibm_temps, 0)
2291 CRIT_ERR("ibm_temps: needs an argument");
2293 if (!isdigit(arg[0])
2295 || atoi(&arg[0]) >=8)
2298 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2300 obj->data.sensor = atoi(&arg[0]);
2301 END OBJ(ibm_volume, 0)
2302 END OBJ(ibm_brightness, 0)
2303 END OBJ(pb_battery, 0)
2304 if (arg && strcmp(arg, "status") == 0) {
2305 obj->data.i = PB_BATT_STATUS;
2306 } else if (arg && strcmp(arg, "percent") == 0) {
2307 obj->data.i = PB_BATT_PERCENT;
2308 } else if (arg && strcmp(arg, "time") == 0) {
2309 obj->data.i = PB_BATT_TIME;
2311 ERR("pb_battery: needs one argument: status, percent or time");
2316 #endif /* __linux__ */
2317 #if defined(__OpenBSD__)
2318 END OBJ(obsd_sensors_temp, 0);
2320 CRIT_ERR("obsd_sensors_temp: needs an argument");
2322 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2324 ERR("Invalid temperature sensor number!");
2326 obj->data.sensor = atoi(&arg[0]);
2327 END OBJ(obsd_sensors_fan, 0);
2329 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2331 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2333 ERR("Invalid fan sensor number!");
2335 obj->data.sensor = atoi(&arg[0]);
2336 END OBJ(obsd_sensors_volt, 0);
2338 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2340 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2342 ERR("Invalid voltage sensor number!");
2344 obj->data.sensor = atoi(&arg[0]);
2345 END OBJ(obsd_vendor, 0);
2346 END OBJ(obsd_product, 0);
2347 #endif /* __OpenBSD__ */
2348 END OBJ(buffers, INFO_BUFFERS)
2349 END OBJ(cached, INFO_BUFFERS)
2350 END OBJ(cpu, INFO_CPU)
2352 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2353 obj->data.cpu_index = atoi(&arg[3]);
2355 } else {obj->data.cpu_index = 0; }
2357 obj->data.cpu_index = 0;
2359 END OBJ(cpubar, INFO_CPU)
2361 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2362 obj->data.cpu_index = atoi(&arg[3]);
2365 else {obj->data.cpu_index = 0;}
2366 (void) scan_bar(arg, &obj->a, &obj->b);
2368 (void) scan_bar(arg, &obj->a, &obj->b);
2369 obj->data.cpu_index = 0;
2371 END OBJ(cpugraph, INFO_CPU)
2373 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2374 obj->data.cpu_index = atoi(&arg[3]);
2377 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2379 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2380 obj->data.cpu_index = 0;
2382 END OBJ(diskio, INFO_DISKIO)
2383 END OBJ(diskio_read, INFO_DISKIO)
2384 END OBJ(diskio_write, INFO_DISKIO)
2385 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2386 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2387 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2390 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2393 obj->data.l = color0;
2395 obj->data.l = color1;
2397 obj->data.l = color2;
2399 obj->data.l = color3;
2401 obj->data.l = color4;
2403 obj->data.l = color5;
2405 obj->data.l = color6;
2407 obj->data.l = color7;
2409 obj->data.l = color8;
2411 obj->data.l = color9;
2413 obj->data.s = scan_font(arg);
2414 END OBJ(downspeed, INFO_NET)
2416 obj->data.net = get_net_stat(arg);
2419 CRIT_ERR("downspeed needs argument");
2421 END OBJ(downspeedf, INFO_NET)
2423 obj->data.net = get_net_stat(arg);
2426 CRIT_ERR("downspeedf needs argument");
2428 END OBJ(downspeedgraph, INFO_NET)
2429 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2431 sscanf(arg, "%63s %*i,%*i %*i", buf);
2432 obj->data.net = get_net_stat(buf);
2433 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2434 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2441 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2442 blockstart[blockdepth - 1] = object_count;
2443 obj->data.ifblock.pos = object_count + 2;
2445 ERR("$else: no matching $if_*");
2450 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2452 ERR("$endif: no matching $if_*");
2455 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2458 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2459 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2460 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2461 END OBJ(execibar, 0) unsigned int n;
2462 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2464 ERR("${execibar <interval> command}");
2465 obj->type = OBJ_text;
2466 snprintf(buf, 256, "${%s}", s);
2467 obj->data.s = strdup(buf);
2469 obj->data.execi.cmd = strdup(arg + n);
2471 END OBJ(execigraph, 0) unsigned int n;
2472 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2474 ERR("${execigraph <interval> command}");
2475 obj->type = OBJ_text;
2476 snprintf(buf, 256, "${%s}", s);
2477 obj->data.s = strdup(buf);
2479 obj->data.execi.cmd = strdup(arg + n);
2481 END OBJ(execi, 0) unsigned int n;
2482 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2484 ERR("${execi <interval> command}");
2485 obj->type = OBJ_text;
2486 snprintf(buf, 256, "${%s}", s);
2487 obj->data.s = strdup(buf);
2489 obj->data.execi.cmd = strdup(arg + n);
2490 obj->data.execi.buffer =
2491 (char *) calloc(1, text_buffer_size);
2493 END OBJ(texeci, 0) unsigned int n;
2494 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2496 ERR("${texeci <interval> command}");
2497 obj->type = OBJ_text;
2498 snprintf(buf, 256, "${%s}", s);
2499 obj->data.s = strdup(buf);
2501 obj->data.texeci.cmd = strdup(arg + n);
2502 obj->data.texeci.buffer =
2503 (char *) calloc(1, text_buffer_size);
2505 obj->data.texeci.p_timed_thread = NULL;
2506 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2508 FILE *fp = popen(arg, "r");
2512 n = fread(buf, 1, 2048, fp);
2515 if (n && buf[n - 1] == '\n')
2520 obj->data.s = strdup(buf);
2522 obj->data.s = strdup("");
2525 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2526 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2528 while (isspace(*arg))
2534 obj->data.fsbar.fs = prepare_fs_stat(arg);
2535 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2538 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2542 obj->data.fsbar.fs = prepare_fs_stat(arg);
2543 END OBJ(fs_free, INFO_FS) if (!arg)
2545 obj->data.fs = prepare_fs_stat(arg);
2546 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2548 obj->data.fs = prepare_fs_stat(arg);
2549 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2551 obj->data.fs = prepare_fs_stat(arg);
2552 END OBJ(fs_size, INFO_FS) if (!arg)
2554 obj->data.fs = prepare_fs_stat(arg);
2555 END OBJ(fs_used, INFO_FS) if (!arg)
2557 obj->data.fs = prepare_fs_stat(arg);
2558 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2559 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2560 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2564 ERR("goto needs arguments");
2565 obj->type = OBJ_text;
2566 obj->data.s = strdup("${goto}");
2570 obj->data.i = atoi(arg);
2575 if (sscanf(arg, "%d %d", &a, &b) != 2)
2576 sscanf(arg, "%d", &b);
2580 obj->data.pair.a = a;
2581 obj->data.pair.b = b;
2584 END OBJ(i2c, INFO_SYSFS)
2585 char buf1[64], buf2[64];
2589 ERR("i2c needs arguments");
2590 obj->type = OBJ_text;
2591 //obj->data.s = strdup("${i2c}");
2595 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2596 /* if scanf couldn't read three values, read type and num and use default device */
2597 sscanf(arg, "%63s %d", buf2, &n);
2598 obj->data.sysfs.fd =
2599 open_i2c_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2600 strncpy(obj->data.sysfs.type, buf2, 63);
2602 obj->data.sysfs.fd =
2603 open_i2c_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2604 strncpy(obj->data.sysfs.type, buf2, 63);
2607 END OBJ(platform, INFO_SYSFS)
2608 char buf1[64], buf2[64];
2612 ERR("platform needs arguments");
2613 obj->type = OBJ_text;
2617 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2618 /* if scanf couldn't read three values, read type and num and use default device */
2619 sscanf(arg, "%63s %d", buf2, &n);
2620 obj->data.sysfs.fd =
2621 open_platform_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2622 strncpy(obj->data.sysfs.type, buf2, 63);
2624 obj->data.sysfs.fd =
2625 open_platform_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2626 strncpy(obj->data.sysfs.type, buf2, 63);
2629 END OBJ(hwmon, INFO_SYSFS)
2630 char buf1[64], buf2[64];
2634 ERR("hwmon needs argumanets");
2635 obj->type = OBJ_text;
2639 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2640 /* if scanf couldn't read three values, read type and num and use default device */
2641 sscanf(arg, "%63s %d", buf2, &n);
2642 obj->data.sysfs.fd =
2643 open_hwmon_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2644 strncpy(obj->data.sysfs.type, buf2, 63);
2646 obj->data.sysfs.fd =
2647 open_hwmon_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2648 strncpy(obj->data.sysfs.type, buf2, 63);
2650 #endif /* !__OpenBSD__ */
2652 END OBJ(top, INFO_TOP)
2656 ERR("top needs arguments");
2657 obj->type = OBJ_text;
2658 //obj->data.s = strdup("${top}");
2661 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2662 if (strcmp(buf, "name") == 0) {
2663 obj->data.top.type = TOP_NAME;
2664 } else if (strcmp(buf, "cpu") == 0) {
2665 obj->data.top.type = TOP_CPU;
2666 } else if (strcmp(buf, "pid") == 0) {
2667 obj->data.top.type = TOP_PID;
2668 } else if (strcmp(buf, "mem") == 0) {
2669 obj->data.top.type = TOP_MEM;
2671 ERR("invalid arg for top");
2674 if (n < 1 || n > 10) {
2675 CRIT_ERR("invalid arg for top");
2678 obj->data.top.num = n - 1;
2682 ERR("invalid args given for top");
2685 END OBJ(top_mem, INFO_TOP)
2689 ERR("top_mem needs arguments");
2690 obj->type = OBJ_text;
2691 obj->data.s = strdup("${top_mem}");
2694 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2695 if (strcmp(buf, "name") == 0) {
2696 obj->data.top.type = TOP_NAME;
2697 } else if (strcmp(buf, "cpu") == 0) {
2698 obj->data.top.type = TOP_CPU;
2699 } else if (strcmp(buf, "pid") == 0) {
2700 obj->data.top.type = TOP_PID;
2701 } else if (strcmp(buf, "mem") == 0) {
2702 obj->data.top.type = TOP_MEM;
2704 ERR("invalid arg for top");
2707 if (n < 1 || n > 10) {
2708 CRIT_ERR("invalid arg for top");
2711 obj->data.top.num = n - 1;
2715 ERR("invalid args given for top");
2718 END OBJ(addr, INFO_NET)
2720 obj->data.net = get_net_stat(arg);
2723 CRIT_ERR("addr needs argument");
2730 ERR("tail needs arguments");
2731 obj->type = OBJ_text;
2732 obj->data.s = strdup("${tail}");
2735 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2736 if (n1 < 1 || n1 > 30) {
2737 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2743 obj->data.tail.fd = -1;
2745 if (stat(buf, &st) == 0) {
2746 if (S_ISFIFO(st.st_mode)) {
2747 fd = open(buf, O_RDONLY|O_NONBLOCK);
2750 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2752 obj->data.tail.fd = fd;
2756 fp = fopen(buf, "r");
2759 if (fp || obj->data.tail.fd != -1) {
2760 obj->data.tail.logfile =
2761 malloc(text_buffer_size);
2762 strcpy(obj->data.tail.logfile, buf);
2763 obj->data.tail.wantedlines = n1;
2764 obj->data.tail.interval =
2765 update_interval * 2;
2767 if (obj->data.tail.fd == -1)
2771 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2774 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2775 if (n1 < 1 || n1 > 30) {
2777 ("invalid arg for tail, number of lines must be between 1 and 30");
2779 } else if (n2 < 1 || n2 < update_interval) {
2781 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2787 obj->data.tail.fd = -1;
2789 if (stat(buf, &st) == 0) {
2790 if (S_ISFIFO(st.st_mode)) {
2791 fd = open(buf, O_RDONLY|O_NONBLOCK);
2794 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2796 obj->data.tail.fd = fd;
2799 fp = fopen(buf, "r");
2802 if (fp || obj->data.tail.fd != -1) {
2803 obj->data.tail.logfile =
2804 malloc(text_buffer_size);
2805 strcpy(obj->data.tail.logfile, buf);
2806 obj->data.tail.wantedlines = n1;
2807 obj->data.tail.interval = n2;
2809 if (obj->data.tail.fd == -1)
2813 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2819 ERR("invalid args given for tail");
2822 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2827 ERR("head needs arguments");
2828 obj->type = OBJ_text;
2829 obj->data.s = strdup("${head}");
2832 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2833 if (n1 < 1 || n1 > 30) {
2834 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2838 fp = fopen(buf, "r");
2840 obj->data.tail.logfile =
2841 malloc(text_buffer_size);
2842 strcpy(obj->data.tail.logfile, buf);
2843 obj->data.tail.wantedlines = n1;
2844 obj->data.tail.interval =
2845 update_interval * 2;
2849 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2852 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2853 if (n1 < 1 || n1 > 30) {
2855 ("invalid arg for head, number of lines must be between 1 and 30");
2857 } else if (n2 < 1 || n2 < update_interval) {
2859 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2863 fp = fopen(buf, "r");
2865 obj->data.tail.logfile =
2866 malloc(text_buffer_size);
2867 strcpy(obj->data.tail.logfile, buf);
2868 obj->data.tail.wantedlines = n1;
2869 obj->data.tail.interval = n2;
2873 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2879 ERR("invalid args given for head");
2882 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2883 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2885 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2886 if (r >= 3 && (c < 1 || c > 3))
2888 if (r >= 2 && (b < 1 || b > 3))
2890 if (r >= 1 && (a < 1 || a > 3))
2893 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2894 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2895 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2896 END OBJ(if_empty, 0)
2897 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2898 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2901 ERR("if_empty needs an argument");
2902 obj->data.ifblock.s = 0;
2904 obj->data.ifblock.s = strdup(arg);
2905 blockstart[blockdepth] = object_count;
2906 obj->data.ifblock.pos = object_count + 2;
2908 END OBJ(if_existing, 0)
2909 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2910 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2913 ERR("if_existing needs an argument or two");
2914 obj->data.ifblock.s = NULL;
2915 obj->data.ifblock.str = NULL;
2917 char buf1[256], buf2[256];
2918 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2920 obj->data.ifblock.s = strdup(buf1);
2921 obj->data.ifblock.str = NULL;
2923 obj->data.ifblock.s = strdup(buf1);
2924 obj->data.ifblock.str = strdup(buf2);
2927 blockstart[blockdepth] = object_count;
2928 obj->data.ifblock.pos = object_count + 2;
2930 END OBJ(if_mounted, 0)
2931 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2932 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2935 ERR("if_mounted needs an argument");
2936 obj->data.ifblock.s = 0;
2938 obj->data.ifblock.s = strdup(arg);
2939 blockstart[blockdepth] = object_count;
2940 obj->data.ifblock.pos = object_count + 2;
2942 END OBJ(if_running, 0)
2943 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2944 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2948 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2949 obj->data.ifblock.s = strdup(buf);
2951 ERR("if_running needs an argument");
2952 obj->data.ifblock.s = 0;
2954 blockstart[blockdepth] = object_count;
2955 obj->data.ifblock.pos = object_count + 2;
2961 char box[256], dst[256];
2965 strncpy(box, MAIL_FILE, sizeof(box));
2968 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2970 strncpy(box, arg, sizeof(box));
2974 variable_substitute(box, dst, sizeof(dst));
2975 obj->data.local_mail.box = strdup(dst);
2976 obj->data.local_mail.interval = n1;
2979 END OBJ(mboxscan, 0)
2980 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2981 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2982 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2983 obj->data.mboxscan.output[0] = 1;
2984 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2985 END OBJ(mem, INFO_MEM)
2986 END OBJ(memmax, INFO_MEM)
2987 END OBJ(memperc, INFO_MEM)
2988 END OBJ(membar, INFO_MEM)
2989 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2990 END OBJ(memgraph, INFO_MEM)
2991 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2992 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2993 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2994 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2995 END OBJ(mixerbar, INFO_MIXER)
2996 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2997 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2998 END OBJ(mixerlbar, INFO_MIXER)
2999 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3000 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3001 END OBJ(mixerrbar, INFO_MIXER)
3002 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3003 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3007 char box[256], dst[256];
3011 strncpy(box, MAIL_FILE, sizeof(box));
3014 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3016 strncpy(box, arg, sizeof(box));
3020 variable_substitute(box, dst, sizeof(dst));
3021 obj->data.local_mail.box = strdup(dst);
3022 obj->data.local_mail.interval = n1;
3025 END OBJ(nodename, 0)
3026 END OBJ(processes, INFO_PROCS)
3027 END OBJ(running_processes, INFO_RUN_PROCS)
3028 END OBJ(shadecolor, 0)
3030 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3032 END OBJ(outlinecolor, 0)
3034 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3036 END OBJ(stippled_hr, 0)
3038 int a = stippled_borders, b = 1;
3040 if (sscanf(arg, "%d %d", &a, &b) != 2)
3041 sscanf(arg, "%d", &b);
3045 obj->data.pair.a = a;
3046 obj->data.pair.b = b;
3048 END OBJ(swap, INFO_MEM)
3049 END OBJ(swapmax, INFO_MEM)
3050 END OBJ(swapperc, INFO_MEM)
3051 END OBJ(swapbar, INFO_MEM)
3052 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3055 END OBJ(temp1, INFO_SYSFS) obj->type = OBJ_i2c;
3056 obj->data.sysfs.fd =
3057 open_i2c_sensor(0, "temp", 1, &obj->data.sysfs.arg,
3058 obj->data.sysfs.devtype);
3059 END OBJ(temp2, INFO_SYSFS) obj->type = OBJ_i2c;
3060 obj->data.sysfs.fd =
3061 open_i2c_sensor(0, "temp", 2, &obj->data.sysfs.arg,
3062 obj->data.sysfs.devtype);
3064 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3065 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3067 char buf1[256], buf2[256], *fmt, *tz;
3070 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3079 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3080 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3082 END OBJ(iconv_start, 0)
3083 if (iconv_converting) {
3084 CRIT_ERR("You must stop your last iconv conversion before starting another");
3087 char iconv_from[CODEPAGE_LENGTH];
3088 char iconv_to[CODEPAGE_LENGTH];
3089 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3090 CRIT_ERR("Invalid arguments for iconv_start");
3093 new_iconv = iconv_open(iconv_to, iconv_from);
3094 if (new_iconv == (iconv_t)(-1)) {
3095 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3097 obj->a = register_iconv(&new_iconv);
3098 iconv_converting = 1;
3102 CRIT_ERR("Iconv requires arguments");
3104 END OBJ(iconv_stop, 0)
3105 iconv_converting = 0;
3108 END OBJ(totaldown, INFO_NET)
3110 obj->data.net = get_net_stat(arg);
3113 CRIT_ERR("totaldown needs argument");
3115 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
3117 obj->data.net = get_net_stat(arg);
3120 CRIT_ERR("totalup needs argument");
3123 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
3124 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
3125 END OBJ(upspeed, INFO_NET)
3127 obj->data.net = get_net_stat(arg);
3130 CRIT_ERR("upspeed needs argument");
3132 END OBJ(upspeedf, INFO_NET)
3134 obj->data.net = get_net_stat(arg);
3137 CRIT_ERR("upspeedf needs argument");
3140 END OBJ(upspeedgraph, INFO_NET)
3141 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
3143 sscanf(arg, "%63s %*i,%*i %*i", buf);
3144 obj->data.net = get_net_stat(buf);
3145 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
3146 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
3151 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3153 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3154 #endif /* !__OpenBSD__ */
3155 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3156 OBJ(apm_adapter, 0) END
3157 OBJ(apm_battery_life, 0) END
3158 OBJ(apm_battery_time, 0) END
3159 #endif /* __FreeBSD__ */
3163 obj->data.mail = parse_mail_args(IMAP, arg);
3164 obj->global_mode = 0;
3166 obj->global_mode = 1;
3169 OBJ(imap_messages, 0)
3172 obj->data.mail = parse_mail_args(IMAP, arg);
3173 obj->global_mode = 0;
3175 obj->global_mode = 1;
3181 obj->data.mail = parse_mail_args(POP3, arg);
3182 obj->global_mode = 0;
3184 obj->global_mode = 1;
3190 obj->data.mail = parse_mail_args(POP3, arg);
3191 obj->global_mode = 0;
3193 obj->global_mode = 1;
3197 OBJ(mpd_artist, INFO_MPD) END
3198 OBJ(mpd_title, INFO_MPD)
3201 sscanf (arg, "%d", &info.mpd.max_title_len);
3202 if (info.mpd.max_title_len > 0) {
3203 info.mpd.max_title_len++;
3205 CRIT_ERR ("mpd_title: invalid length argument");
3208 info.mpd.max_title_len = 0;
3211 END OBJ(mpd_random, INFO_MPD)
3212 END OBJ(mpd_repeat, INFO_MPD)
3213 END OBJ(mpd_elapsed, INFO_MPD)
3214 END OBJ(mpd_length, INFO_MPD)
3215 END OBJ(mpd_track, INFO_MPD)
3216 END OBJ(mpd_name, INFO_MPD)
3217 END OBJ(mpd_file, INFO_MPD)
3218 END OBJ(mpd_percent, INFO_MPD)
3219 END OBJ(mpd_album, INFO_MPD)
3220 END OBJ(mpd_vol, INFO_MPD)
3221 END OBJ(mpd_bitrate, INFO_MPD)
3222 END OBJ(mpd_status, INFO_MPD)
3223 END OBJ(mpd_bar, INFO_MPD)
3224 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3225 END OBJ(mpd_smart, INFO_MPD) END
3228 OBJ(xmms2_artist, INFO_XMMS2)
3229 END OBJ(xmms2_album, INFO_XMMS2)
3230 END OBJ(xmms2_title, INFO_XMMS2)
3231 END OBJ(xmms2_genre, INFO_XMMS2)
3232 END OBJ(xmms2_comment, INFO_XMMS2)
3233 END OBJ(xmms2_decoder, INFO_XMMS2)
3234 END OBJ(xmms2_transport, INFO_XMMS2)
3235 END OBJ(xmms2_url, INFO_XMMS2)
3236 END OBJ(xmms2_tracknr, INFO_XMMS2)
3237 END OBJ(xmms2_bitrate, INFO_XMMS2)
3238 END OBJ(xmms2_date, INFO_XMMS2)
3239 END OBJ(xmms2_id, INFO_XMMS2)
3240 END OBJ(xmms2_duration, INFO_XMMS2)
3241 END OBJ(xmms2_elapsed, INFO_XMMS2)
3242 END OBJ(xmms2_size, INFO_XMMS2)
3243 END OBJ(xmms2_status, INFO_XMMS2)
3244 END OBJ(xmms2_percent, INFO_XMMS2)
3245 END OBJ(xmms2_bar, INFO_XMMS2)
3246 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3247 END OBJ(xmms2_smart, INFO_XMMS2)
3251 OBJ(audacious_status, INFO_AUDACIOUS) END
3252 OBJ(audacious_title, INFO_AUDACIOUS)
3255 sscanf (arg, "%d", &info.audacious.max_title_len);
3256 if (info.audacious.max_title_len > 0) {
3257 info.audacious.max_title_len++;
3259 CRIT_ERR ("audacious_title: invalid length argument");
3264 OBJ(audacious_length, INFO_AUDACIOUS) END
3265 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3266 OBJ(audacious_position, INFO_AUDACIOUS) END
3267 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3268 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3269 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3270 OBJ(audacious_channels, INFO_AUDACIOUS) END
3271 OBJ(audacious_filename, INFO_AUDACIOUS) END
3272 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3273 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3274 OBJ(audacious_bar, INFO_AUDACIOUS)
3275 (void) scan_bar(arg, &obj->a, &obj->b);
3279 OBJ(bmpx_title, INFO_BMPX)
3280 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3282 OBJ(bmpx_artist, INFO_BMPX)
3283 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3285 OBJ(bmpx_album, INFO_BMPX)
3286 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3288 OBJ(bmpx_track, INFO_BMPX)
3289 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3291 OBJ(bmpx_uri, INFO_BMPX)
3292 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3294 OBJ(bmpx_bitrate, INFO_BMPX)
3295 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3301 int argc, delay, act_par;
3302 char *uri = (char *)malloc(128 * sizeof(char));
3303 char *action = (char *)malloc(64 * sizeof(char));
3305 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3306 obj->data.rss.uri = uri;
3307 obj->data.rss.delay = delay;
3308 obj->data.rss.action = action;
3309 obj->data.rss.act_par = act_par;
3313 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3319 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3320 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3321 ERR("hddtemp needs arguments");
3322 obj->type = OBJ_text;
3323 obj->data.s = strdup("${hddtemp}");
3328 #ifdef TCP_PORT_MONITOR
3329 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3330 int argc, port_begin, port_end, item, connection_index;
3332 memset(itembuf,0,sizeof(itembuf));
3334 /* massive argument checking */
3336 CRIT_ERR("tcp_portmon: needs arguments");
3338 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3339 if ( (argc != 3) && (argc != 4) )
3341 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3343 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3345 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3347 if ( port_begin > port_end )
3349 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3351 if ( strncmp(itembuf,"count",31) == 0 )
3353 else if ( strncmp(itembuf,"rip",31) == 0 )
3355 else if ( strncmp(itembuf,"rhost",31) == 0 )
3357 else if ( strncmp(itembuf,"rport",31) == 0 )
3359 else if ( strncmp(itembuf,"rservice",31) == 0 )
3361 else if ( strncmp(itembuf,"lip",31) == 0 )
3363 else if ( strncmp(itembuf,"lhost",31) == 0 )
3365 else if ( strncmp(itembuf,"lport",31) == 0 )
3367 else if ( strncmp(itembuf,"lservice",31) == 0 )
3371 CRIT_ERR("tcp_portmon: invalid item specified");
3373 if ( (argc==3) && (item!=COUNT) )
3375 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3377 if ( (argc==4) && (connection_index<0) )
3379 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3381 /* ok, args looks good. save the text object data */
3382 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3383 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3384 obj->data.tcp_port_monitor.item = item;
3385 obj->data.tcp_port_monitor.connection_index = connection_index;
3387 /* if the port monitor collection hasn't been created, we must create it */
3388 if ( !info.p_tcp_port_monitor_collection )
3390 info.p_tcp_port_monitor_collection =
3391 create_tcp_port_monitor_collection ();
3392 if ( !info.p_tcp_port_monitor_collection )
3394 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3398 /* if a port monitor for this port does not exist, create one and add it to the collection */
3399 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3401 tcp_port_monitor_t * p_monitor =
3402 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3405 CRIT_ERR("tcp_portmon: unable to create port monitor");
3407 /* add the newly created monitor to the collection */
3408 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3411 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3416 OBJ(entropy_avail, INFO_ENTROPY) END
3417 OBJ(entropy_poolsize, INFO_ENTROPY) END
3418 OBJ(entropy_bar, INFO_ENTROPY)
3419 (void) scan_bar(arg, &obj->a, &obj->b);
3424 ERR("unknown variable %s", s);
3425 obj->type = OBJ_text;
3426 snprintf(buf, 256, "${%s}", s);
3427 obj->data.s = strdup(buf);
3434 static struct text_object *create_plain_text(const char *s)
3436 struct text_object *obj;
3438 if (s == NULL || *s == '\0') {
3442 obj = new_text_object_internal();
3444 obj->type = OBJ_text;
3445 obj->data.s = strdup(s);
3449 static struct text_object_list *extract_variable_text_internal(const char *p)
3451 struct text_object_list *retval;
3452 struct text_object *obj;
3455 retval = malloc(sizeof(struct text_object_list));
3456 memset(retval, 0, sizeof(struct text_object_list));
3457 retval->text_object_count = 0;
3459 long line = text_lines;
3467 obj = create_plain_text(s);
3469 // allocate memory for the object
3470 retval->text_objects = realloc(retval->text_objects,
3471 sizeof(struct text_object) * (retval->text_object_count+1));
3472 // assign the new object to the end of the list.
3473 memcpy(&retval->text_objects[retval->text_object_count++],
3474 obj, sizeof(struct text_object));
3486 /* variable is either $foo or ${foo} */
3488 unsigned int brl = 1, brr = 0;
3491 while (*p && brl != brr) {
3492 if (*p == '{') brl++;
3493 if (*p == '}') brr++;
3501 while (*p && (isalnum((int) *p)
3506 /* copy variable to buffer */
3507 len = (p - s > 255) ? 255 : (p - s);
3508 strncpy(buf, s, len);
3517 /* if variable wasn't found from environment, use some special */
3523 if (strchr(buf, ' ')) {
3524 arg = strchr(buf, ' ');
3527 while (isspace((int) *arg))
3533 /* lowercase variable name */
3540 // create new object
3541 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3543 // allocate memory for the object
3544 retval->text_objects = realloc(retval->text_objects,
3545 sizeof(struct text_object) * (retval->text_object_count+1));
3546 // assign the new object to the end of the list.
3547 memcpy(&retval->text_objects[retval->text_object_count++],
3548 obj, sizeof(struct text_object));
3554 obj = create_plain_text("$");
3556 // allocate memory for the object
3557 retval->text_objects = realloc(retval->text_objects,
3558 sizeof(struct text_object) * (retval->text_object_count+1));
3559 // assign the new object to the end of the list.
3560 memcpy(&retval->text_objects[retval->text_object_count++],
3561 obj, sizeof(struct text_object));
3568 obj = create_plain_text(s);
3570 // allocate memory for the object
3571 retval->text_objects = realloc(retval->text_objects,
3572 sizeof(struct text_object) * (retval->text_object_count+1));
3573 // assign the new object to the end of the list.
3574 memcpy(&retval->text_objects[retval->text_object_count++],
3575 obj, sizeof(struct text_object));
3580 ERR("one or more $endif's are missing");
3586 static void extract_variable_text(const char *p)
3588 struct text_object_list *list;
3590 free_text_objects(text_object_count, text_objects);
3591 text_object_count = 0;
3592 text_objects = NULL;
3595 list = extract_variable_text_internal(p);
3596 text_objects = list->text_objects;
3597 text_object_count = list->text_object_count;
3604 void parse_conky_vars(char * text, char * p, struct information *cur) {
3605 struct text_object_list *object_list = extract_variable_text_internal(text);
3606 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3611 * Allows reading from a FIFO (i.e., /dev/xconsole). The file descriptor is
3612 * set to non-blocking which makes this possible.
3615 * Since lseek cannot seek a file descriptor long lines will break.
3617 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
3619 #define TAIL_PIPE_BUFSIZE 4096
3623 int fd = obj->data.tail.fd;
3626 char buf[TAIL_PIPE_BUFSIZE];
3627 ssize_t len = read(fd, buf, sizeof(buf));
3631 if (errno != EAGAIN) {
3632 strcpy(obj->data.tail.buffer, "Logfile Read Error");
3633 snprintf(dst, dst_size, "Logfile Read Error");
3638 else if (len == 0) {
3639 strcpy(obj->data.tail.buffer, "Logfile Empty");
3640 snprintf(dst, dst_size, "Logfile Empty");
3644 for (line_len = 0, i = 0; i < len; i++) {
3648 if (buf[i] == '\n') {
3651 if (obj->data.tail.readlines > 0) {
3656 for (n = 0; obj->data.tail.buffer[n]; n++) {
3657 if (obj->data.tail.buffer[n] == '\n') {
3661 if (++olines < obj->data.tail.wantedlines) {
3667 p = obj->data.tail.buffer + first_line;
3668 pos = n - first_line;
3669 memmove(obj->data.tail.buffer, obj->data.tail.buffer + first_line, strlen(p));
3670 obj->data.tail.buffer[pos] = 0;
3676 p = buf + last_line;
3678 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
3679 obj->data.tail.buffer[pos + line_len] = 0;
3682 obj->data.tail.readlines = lines;
3690 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
3693 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3698 char buff_in[P_MAX_SIZE] = {0};
3699 iconv_converting = 0;
3702 for (i = 0; i < object_count; i++) {
3703 struct text_object *obj = &objs[i];
3705 #define OBJ(a) break; case OBJ_##a:
3707 switch (obj->type) {
3710 ERR("not implemented obj type %d",
3715 /* does anyone have decimals in acpi temperature? */
3717 snprintf(p, p_max_size, "%d", (int)
3718 get_acpi_temperature(obj->
3722 snprintf(p, 5, "%d ", (int)
3723 get_acpi_temperature(obj->
3728 /* does anyone have decimals in acpi temperature? */
3730 snprintf(p, p_max_size, "%d", (int)
3731 ((get_acpi_temperature(obj->
3733 i)+ 40) * 9.0 / 5 - 40));
3735 snprintf(p, 5, "%d ", (int)
3736 ((get_acpi_temperature(obj->
3738 i)+ 40) * 9.0 / 5 - 40));
3740 #endif /* !__OpenBSD__ */
3743 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3749 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3751 /* OpenBSD has no such flag (SUSv2) */
3752 obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->data.cpu_index);
3757 #if defined(__linux__)
3760 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3765 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3769 OBJ(wireless_essid) {
3770 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3772 OBJ(wireless_mode) {
3773 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3775 OBJ(wireless_bitrate) {
3776 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3779 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3781 OBJ(wireless_link_qual) {
3783 snprintf(p, p_max_size, "%d", obj->data.net->link_qual);
3785 snprintf(p, 4, "%d ", obj->data.net->link_qual);
3787 OBJ(wireless_link_qual_max) {
3789 snprintf(p, p_max_size, "%d", obj->data.net->link_qual_max);
3791 snprintf(p, 4, "%d ", obj->data.net->link_qual_max);
3793 OBJ(wireless_link_qual_perc) {
3794 if(obj->data.net->link_qual_max > 0) {
3796 snprintf(p, p_max_size, "%.0f%%", (double)obj->data.net->link_qual / obj->data.net->link_qual_max * 100);
3798 snprintf(p, 5, "%.0f%% ", (double)obj->data.net->link_qual / obj->data.net->link_qual_max * 100);
3799 } else snprintf(p, p_max_size, "unk");
3801 OBJ(wireless_link_bar) {
3802 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3804 #endif /* HAVE_IWLIB */
3806 #endif /* __linux__ */
3810 get_freq_dynamic(p, 6, "%.0f ", 1 );
3812 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3818 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3820 get_freq_dynamic(p, 6, "%.2f ", 1000);
3824 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3826 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
3832 get_adt746x_cpu(p, p_max_size);
3835 get_adt746x_fan(p, p_max_size);
3838 get_acpi_fan(p, p_max_size);
3840 OBJ(acpiacadapter) {
3841 get_acpi_ac_adapter(p, p_max_size);
3844 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3847 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3849 OBJ(battery_percent) {
3850 snprintf(p, p_max_size, "%d",
3851 get_battery_perct(obj->data.s));
3854 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3856 #endif /* __OpenBSD__ */
3858 human_readable(cur->buffers * 1024, p, 255);
3861 human_readable(cur->cached * 1024, p, 255);
3864 if (obj->data.cpu_index > info.cpu_count) {
3865 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3866 CRIT_ERR("attempting to use more CPUs then you have!");
3869 snprintf(p, p_max_size, "%*d", pad_percents,
3870 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3873 snprintf(p, 4, "%*d ",
3875 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3881 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3884 new_graph(p, obj->a,
3885 obj->b, obj->c, obj->d,
3886 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3890 new_fg(p, obj->data.l);
3922 #if defined(__linux__)
3924 snprintf(p, p_max_size, "%s", i8k.version);
3927 snprintf(p, p_max_size, "%s", i8k.bios);
3930 snprintf(p, p_max_size, "%s", i8k.serial);
3933 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3935 OBJ(i8k_cpu_tempf) {
3937 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3938 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3940 OBJ(i8k_left_fan_status) {
3941 int left_fan_status;
3942 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3943 if(left_fan_status == 0) {
3944 snprintf(p, p_max_size,"off");
3945 } if(left_fan_status == 1) {
3946 snprintf(p, p_max_size, "low");
3947 } if(left_fan_status == 2) {
3948 snprintf(p, p_max_size, "high");
3952 OBJ(i8k_right_fan_status) {
3953 int right_fan_status;
3954 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3955 if(right_fan_status == 0) {
3956 snprintf(p, p_max_size,"off");
3957 } if(right_fan_status == 1) {
3958 snprintf(p, p_max_size, "low");
3959 } if(right_fan_status == 2) {
3960 snprintf(p, p_max_size, "high");
3963 OBJ(i8k_left_fan_rpm) {
3964 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3966 OBJ(i8k_right_fan_rpm) {
3967 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3969 OBJ(i8k_ac_status) {
3971 sscanf(i8k.ac_status, "%d", &ac_status);
3972 if(ac_status == -1) {
3973 snprintf(p, p_max_size,"disabled (read i8k docs)");
3974 } if(ac_status == 0) {
3975 snprintf(p, p_max_size, "off");
3976 } if(ac_status == 1) {
3977 snprintf(p, p_max_size, "on");
3980 OBJ(i8k_buttons_status) {
3981 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3985 get_ibm_acpi_fan(p, p_max_size);
3988 get_ibm_acpi_temps();
3989 snprintf(p, p_max_size, "%d",
3990 ibm_acpi.temps[obj->data.sensor]);
3993 get_ibm_acpi_volume(p, p_max_size);
3995 OBJ(ibm_brightness) {
3996 get_ibm_acpi_brightness(p, p_max_size);
3999 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4001 #endif /* __linux__ */
4004 OBJ(obsd_sensors_temp) {
4005 obsd_sensors.device = sensor_device;
4006 update_obsd_sensors();
4007 snprintf(p, p_max_size, "%.1f",
4008 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4011 OBJ(obsd_sensors_fan) {
4012 obsd_sensors.device = sensor_device;
4013 update_obsd_sensors();
4014 snprintf(p, p_max_size, "%d",
4015 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4018 OBJ(obsd_sensors_volt) {
4019 obsd_sensors.device = sensor_device;
4020 update_obsd_sensors();
4021 snprintf(p, p_max_size, "%.2f",
4022 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4026 get_obsd_vendor(p, p_max_size);
4030 get_obsd_product(p, p_max_size);
4032 #endif /* __OpenBSD__ */
4035 new_font(p, obj->data.s);
4037 void format_diskio(unsigned int diskio_value)
4040 if (diskio_value > 1024*1024) {
4041 snprintf(p, p_max_size, "%.1fGiB",
4042 (double)diskio_value/1024/1024);
4043 } else if (diskio_value > 1024) {
4044 snprintf(p, p_max_size, "%.1fMiB",
4045 (double)diskio_value/1024);
4046 } else if (diskio_value > 0) {
4047 snprintf(p, p_max_size, "%dKiB", diskio_value);
4049 snprintf(p, p_max_size, "%dB", diskio_value);
4052 if (diskio_value > 1024*1024) {
4053 snprintf(p, 12, "%.1fGiB ",
4054 (double)diskio_value/1024/1024);
4055 } else if (diskio_value > 1024) {
4056 snprintf(p, 12, "%.1fMiB ",
4057 (double)diskio_value/1024);
4058 } else if (diskio_value > 0) {
4059 snprintf(p, 12, "%dKiB ", diskio_value);
4061 snprintf(p, 12, "%dB ", diskio_value);
4066 format_diskio(diskio_value);
4069 format_diskio(diskio_write_value);
4072 format_diskio(diskio_read_value);
4075 new_graph(p, obj->a,
4076 obj->b, obj->c, obj->d,
4077 diskio_value, obj->e, 1);
4079 OBJ(diskiograph_read) {
4080 new_graph(p, obj->a,
4081 obj->b, obj->c, obj->d,
4082 diskio_read_value, obj->e, 1);
4084 OBJ(diskiograph_write) {
4085 new_graph(p, obj->a,
4086 obj->b, obj->c, obj->d,
4087 diskio_write_value, obj->e, 1);
4091 snprintf(p, p_max_size, "%d",
4092 (int) (obj->data.net->
4096 snprintf(p, 6, "%d ",
4097 (int) (obj->data.net->
4103 snprintf(p, p_max_size, "%.1f",
4105 recv_speed / 1024.0);
4107 snprintf(p, 8, "%.1f ",
4109 recv_speed / 1024.0);
4111 OBJ(downspeedgraph) {
4113 if (obj->data.net->recv_speed == 0)
4114 obj->data.net->recv_speed = 0.01;
4116 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4117 (obj->data.net->recv_speed /
4118 1024.0), obj->e, 1);
4122 i = obj->data.ifblock.pos - 1;
4132 snprintf(p, p_max_size, "%u.%u.%u.%u",
4133 obj->data.net->addr.
4135 obj->data.net->addr.
4137 obj->data.net->addr.
4139 obj->data.net->addr.
4143 #if defined(IMLIB2) && defined(X11)
4148 Imlib_Image image, buffer;
4149 image = imlib_load_image(obj->data.s);
4150 imlib_context_set_image(image);
4153 w = imlib_image_get_width();
4154 h = imlib_image_get_height();
4155 buffer = imlib_create_image(w, h);
4156 imlib_context_set_display(display);
4157 imlib_context_set_drawable(window.drawable);
4158 imlib_context_set_colormap(DefaultColormap(display, screen));
4159 imlib_context_set_visual(DefaultVisual(display, screen));
4160 imlib_context_set_image(buffer);
4161 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
4162 imlib_render_image_on_drawable(text_start_x, text_start_y);
4164 imlib_context_set_image(image);
4171 FILE *fp = popen(obj->data.s, "r");
4172 int length = fread(p, 1, p_max_size, fp);
4175 /*output[length] = '\0';
4176 if (length > 0 && output[length - 1] == '\n') {
4177 output[length - 1] = '\0';
4180 if (length > 0 && p[length - 1] == '\n') {
4181 p[length - 1] = '\0';
4184 //parse_conky_vars(output, p, cur);
4188 FILE *fp = popen(obj->data.s, "r");
4189 int n2 = fread(p, 1, p_max_size, fp);
4193 if (n2 && p[n2 - 1] == '\n')
4202 if (sscanf(p, "%lf", &barnum) == 0) {
4203 ERR("reading execbar value failed (perhaps it's not the correct format?)");
4205 if (barnum > 100 || barnum < 0) {
4206 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
4208 barnum = barnum / 100.0;
4209 new_bar(p, 0, 4, (int) (barnum * 255.0));
4215 FILE *fp = popen(obj->data.s, "r");
4216 int n2 = fread(p, 1, p_max_size, fp);
4220 if (n2 && p[n2 - 1] == '\n')
4229 if (sscanf(p, "%lf", &barnum) == 0) {
4230 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
4232 if (barnum > 100 || barnum < 0) {
4233 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
4235 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
4240 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4241 new_bar(p, 0, 4, (int) obj->f);
4244 FILE *fp = popen(obj->data.execi.cmd, "r");
4245 int n2 = fread(p, 1, p_max_size, fp);
4248 if (n2 && p[n2 - 1] == '\n')
4257 if (sscanf(p, "%f", &barnum) == 0) {
4258 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4260 if (barnum > 100 || barnum < 0) {
4261 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4263 obj->f = 255 * barnum / 100.0;
4264 new_bar(p, 0, 4, (int) obj->f);
4266 obj->data.execi.last_update =
4267 current_update_time;
4271 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4272 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4275 FILE *fp = popen(obj->data.execi.cmd, "r");
4276 int n2 = fread(p, 1, p_max_size, fp);
4279 if (n2 && p[n2 - 1] == '\n')
4288 if (sscanf(p, "%f", &barnum) == 0) {
4289 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4291 if (barnum > 100 || barnum < 0) {
4292 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4295 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4297 obj->data.execi.last_update = current_update_time;
4303 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4304 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4306 char *output = obj->data.execi.buffer;
4307 FILE *fp = popen(obj->data.execi.cmd, "r");
4308 //int length = fread(output, 1, text_buffer_size, fp);
4309 int length = fread(output, 1, text_buffer_size, fp);
4312 output[length] = '\0';
4313 if (length > 0 && output[length - 1] == '\n') {
4314 output[length - 1] = '\0';
4316 obj->data.execi.last_update = current_update_time;
4317 snprintf(p, p_max_size, "%s", output);
4319 //parse_conky_vars(output, p, cur);
4322 if (!obj->data.texeci.p_timed_thread)
4324 obj->data.texeci.p_timed_thread=
4325 timed_thread_create ((void*)threaded_exec, (void*) obj, obj->data.texeci.interval * 1000000);
4326 if (!obj->data.texeci.p_timed_thread)
4327 ERR("Error creating texeci timed thread");
4328 timed_thread_register (obj->data.texeci.p_timed_thread, &obj->data.texeci.p_timed_thread);
4329 if (timed_thread_run (obj->data.texeci.p_timed_thread))
4330 ERR("Error running texeci timed thread");
4332 timed_thread_lock (obj->data.texeci.p_timed_thread);
4333 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4334 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4336 #endif /* HAVE_POPEN */
4338 if (obj->global_mode && info.mail) { // this means we use info
4339 if (!info.mail->p_timed_thread)
4341 info.mail->p_timed_thread =
4342 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4343 if (!info.mail->p_timed_thread)
4344 ERR("Error creating imap timed thread");
4345 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4346 if (timed_thread_run (info.mail->p_timed_thread))
4347 ERR("Error running imap timed thread");
4349 timed_thread_lock (info.mail->p_timed_thread);
4350 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4351 timed_thread_unlock (info.mail->p_timed_thread);
4352 } else if (obj->data.mail) { // this means we use obj
4353 if (!obj->data.mail->p_timed_thread)
4355 obj->data.mail->p_timed_thread =
4356 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4357 obj->data.mail->interval * 1000000);
4358 if (!obj->data.mail->p_timed_thread)
4359 ERR("Error creating imap timed thread");
4360 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4361 if (timed_thread_run (obj->data.mail->p_timed_thread))
4362 ERR("Error running imap timed thread");
4364 timed_thread_lock (obj->data.mail->p_timed_thread);
4365 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4366 timed_thread_unlock (obj->data.mail->p_timed_thread);
4367 } else if (!obj->a) { // something is wrong, warn once then stop
4368 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4372 OBJ(imap_messages) {
4373 if (obj->global_mode && info.mail) { // this means we use info
4374 if (!info.mail->p_timed_thread)
4376 info.mail->p_timed_thread =
4377 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4378 if (!info.mail->p_timed_thread)
4379 ERR("Error creating imap timed thread");
4380 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4381 if (timed_thread_run (info.mail->p_timed_thread))
4382 ERR("Error running imap timed thread");
4384 timed_thread_lock (info.mail->p_timed_thread);
4385 snprintf(p, p_max_size, "%lu", info.mail->messages);
4386 timed_thread_unlock (info.mail->p_timed_thread);
4387 } else if (obj->data.mail) { // this means we use obj
4388 if (!obj->data.mail->p_timed_thread)
4390 obj->data.mail->p_timed_thread =
4391 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4392 obj->data.mail->interval * 1000000);
4393 if (!obj->data.mail->p_timed_thread)
4394 ERR("Error creating imap timed thread");
4395 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4396 if (timed_thread_run (obj->data.mail->p_timed_thread))
4397 ERR("Error runninging imap timed thread");
4399 timed_thread_lock (obj->data.mail->p_timed_thread);
4400 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4401 timed_thread_lock (obj->data.mail->p_timed_thread);
4402 } else if (!obj->a) { // something is wrong, warn once then stop
4403 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4408 if (obj->global_mode && info.mail) { // this means we use info
4409 if (!info.mail->p_timed_thread)
4411 info.mail->p_timed_thread =
4412 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4413 if (!info.mail->p_timed_thread)
4414 ERR("Error creating pop3 timed thread");
4415 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4416 if (timed_thread_run (info.mail->p_timed_thread))
4417 ERR("Error running pop3 timed thread");
4419 timed_thread_lock (info.mail->p_timed_thread);
4420 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4421 timed_thread_unlock (info.mail->p_timed_thread);
4422 } else if (obj->data.mail) { // this means we use obj
4423 if (!obj->data.mail->p_timed_thread)
4425 obj->data.mail->p_timed_thread =
4426 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4427 obj->data.mail->interval * 1000000);
4428 if (!obj->data.mail->p_timed_thread)
4429 ERR("Error creating pop3 timed thread");
4430 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4431 if (timed_thread_run (obj->data.mail->p_timed_thread))
4432 ERR("Error running pop3 timed thread");
4434 timed_thread_lock (obj->data.mail->p_timed_thread);
4435 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4436 timed_thread_unlock (obj->data.mail->p_timed_thread);
4437 } else if (!obj->a) { // something is wrong, warn once then stop
4438 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4443 if (obj->global_mode && info.mail) { // this means we use info
4444 if (!info.mail->p_timed_thread)
4446 info.mail->p_timed_thread =
4447 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4448 if (!info.mail->p_timed_thread)
4449 ERR("Error creating pop3 timed thread");
4450 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4451 if (timed_thread_run (info.mail->p_timed_thread))
4452 ERR("Error running pop3 timed thread");
4454 timed_thread_lock (info.mail->p_timed_thread);
4455 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4456 timed_thread_unlock (info.mail->p_timed_thread);
4457 } else if (obj->data.mail) { // this means we use obj
4458 if (!obj->data.mail->p_timed_thread)
4460 obj->data.mail->p_timed_thread =
4461 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4462 obj->data.mail->interval * 1000000);
4463 if (!obj->data.mail->p_timed_thread)
4464 ERR("Error creating pop3 timed thread");
4465 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4466 if (timed_thread_run (obj->data.mail->p_timed_thread))
4467 ERR("Error running pop3 timed thread");
4469 timed_thread_lock (obj->data.mail->p_timed_thread);
4470 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4471 timed_thread_unlock (obj->data.mail->p_timed_thread);
4472 } else if (!obj->a) { // something is wrong, warn once then stop
4473 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4478 if (obj->data.fs != NULL) {
4479 if (obj->data.fs->size == 0)
4498 if (obj->data.fs != NULL)
4499 human_readable(obj->data.fs->avail,
4503 if (obj->data.fs != NULL) {
4504 if (obj->data.fs->size)
4505 snprintf(p, p_max_size, "%*d",
4514 snprintf(p, p_max_size, "0");
4518 if (obj->data.fs != NULL)
4519 human_readable(obj->data.fs->size,
4523 if (obj->data.fs != NULL)
4524 human_readable(obj->data.fs->size -
4525 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4529 if (obj->data.fs != NULL) {
4530 if (obj->data.fs->size == 0)
4548 if (obj->data.fs != NULL) {
4549 if (obj->data.fs->size)
4550 snprintf(p, 4, "%d",
4560 snprintf(p, p_max_size, "0");
4564 float *v = info.loadavg;
4566 if (obj->data.loadavg[2])
4567 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4568 v[obj->data.loadavg[0] -
4570 v[obj->data.loadavg[1] -
4572 v[obj->data.loadavg[2] -
4574 else if (obj->data.loadavg[1])
4575 snprintf(p, p_max_size, "%.2f %.2f",
4576 v[obj->data.loadavg[0] -
4578 v[obj->data.loadavg[1] -
4580 else if (obj->data.loadavg[0])
4581 snprintf(p, p_max_size, "%.2f",
4582 v[obj->data.loadavg[0] -
4586 new_goto(p, obj->data.i);
4589 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4592 new_hr(p, obj->data.i);
4596 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4599 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4601 if(!strcmp(obj->data.rss.action, "feed_title")) {
4603 if(str[strlen(str)-1] == '\n')
4604 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4605 snprintf(p, p_max_size, "%s", str);
4606 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4607 if(obj->data.rss.act_par < data->item_count) {
4608 str = data->items[obj->data.rss.act_par].title;
4609 if(str[strlen(str)-1] == '\n')
4610 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4611 snprintf(p, p_max_size, "%s", str);
4613 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4614 if(obj->data.rss.act_par < data->item_count) {
4615 str = data->items[obj->data.rss.act_par].description;
4616 if(str[strlen(str)-1] == '\n')
4617 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4618 snprintf(p, p_max_size, "%s", str);
4620 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4621 if(data->item_count > 0) {
4625 if(obj->data.rss.act_par > data->item_count)
4626 show = data->item_count;
4627 else show = obj->data.rss.act_par;
4628 for(itmp = 0; itmp < show; itmp++) {
4629 PRSS_Item *item = &data->items[itmp];
4632 if(itmp>0) // don't add new line before first item
4633 strncat(p, "\n", p_max_size);
4634 if(str[strlen(str)-1] == '\n')
4635 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4636 strncat(p, str, p_max_size);
4649 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4650 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4652 snprintf(p, p_max_size, "N/A");
4653 } else if (unit == '*') {
4654 snprintf(p, p_max_size, "%s", temp);
4656 snprintf(p, p_max_size, "%s°%c", temp, unit);
4661 new_offset(p, obj->data.i);
4664 new_voffset(p, obj->data.i);
4670 r = get_sysfs_info(&obj->data.sysfs.fd,
4671 obj->data.sysfs.arg,
4672 obj->data.sysfs.devtype,
4673 obj->data.sysfs.type);
4675 if (r >= 100.0 || r == 0)
4676 snprintf(p, p_max_size, "%d", (int) r);
4678 snprintf(p, p_max_size, "%.1f", r);
4683 r = get_sysfs_info(&obj->data.sysfs.fd,
4684 obj->data.sysfs.arg,
4685 obj->data.sysfs.devtype,
4686 obj->data.sysfs.type);
4688 if (r >= 100.0 || r == 0)
4689 snprintf(p, p_max_size, "%d", (int) r);
4691 snprintf(p, p_max_size, "%.1f", r);
4696 r = get_sysfs_info(&obj->data.sysfs.fd,
4697 obj->data.sysfs.arg,
4698 obj->data.sysfs.devtype,
4699 obj->data.sysfs.type);
4701 if (r >= 100.0 || r == 0)
4702 snprintf(p, p_max_size, "%d", (int) r);
4704 snprintf(p, p_max_size, "%.1f", r);
4706 #endif /* !__OpenBSD__ */
4708 new_alignr(p, obj->data.i);
4711 new_alignc(p, obj->data.i);
4714 struct information *my_info =
4715 malloc(sizeof(struct information));
4716 memcpy(my_info, cur, sizeof(struct information));
4717 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4718 if (strlen(p) != 0) {
4719 i = obj->data.ifblock.pos;
4729 if ((obj->data.ifblock.s)
4730 && (stat(obj->data.ifblock.s, &tmp) ==
4732 i = obj->data.ifblock.pos;
4735 if (obj->data.ifblock.str) {
4736 if (!check_contains(obj->data.ifblock.s,
4737 obj->data.ifblock.str)) {
4738 i = obj->data.ifblock.pos;
4747 if ((obj->data.ifblock.s)
4748 && (!check_mount(obj->data.ifblock.s))) {
4749 i = obj->data.ifblock.pos;
4756 if ((obj->data.ifblock.s)
4757 && system(obj->data.ifblock.s)) {
4758 i = obj->data.ifblock.pos;
4765 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4768 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4773 human_readable(cur->mem * 1024, p, 255);
4776 human_readable(cur->memmax * 1024, p, 255);
4781 snprintf(p, p_max_size, "%*Lu",
4786 snprintf(p, 4, "%*Lu ",
4793 new_bar(p, obj->data.pair.a,
4795 cur->memmax ? (cur->mem * 255) /
4800 new_graph(p, obj->a,
4801 obj->b, obj->c, obj->d,
4802 cur->memmax ? (cur->mem * 100.0) /
4803 (cur->memmax) : 0.0, 100, 1);
4807 snprintf(p, p_max_size, "%d",
4808 mixer_get_avg(obj->data.l));
4811 snprintf(p, p_max_size, "%d",
4812 mixer_get_left(obj->data.l));
4815 snprintf(p, p_max_size, "%d",
4816 mixer_get_right(obj->data.l));
4819 new_bar(p, obj->data.mixerbar.w,
4820 obj->data.mixerbar.h,
4821 mixer_get_avg(obj->data.mixerbar.
4825 new_bar(p, obj->data.mixerbar.w,
4826 obj->data.mixerbar.h,
4827 mixer_get_left(obj->data.mixerbar.
4831 new_bar(p, obj->data.mixerbar.w,
4832 obj->data.mixerbar.h,
4833 mixer_get_right(obj->data.mixerbar.
4839 update_mail_count(&obj->data.local_mail);
4840 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4843 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4844 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4847 update_mail_count(&obj->data.local_mail);
4848 snprintf(p, p_max_size, "%d", obj->data.local_mail.new_mail_count);
4852 snprintf(p, p_max_size, "%s",
4853 cur->uname_s.nodename);
4856 new_outline(p, obj->data.l);
4860 snprintf(p, p_max_size, "%hu", cur->procs);
4862 snprintf(p, 5, "%hu ",
4865 OBJ(running_processes) {
4867 snprintf(p, p_max_size, "%hu",
4870 snprintf(p, 3, "%hu ",
4874 snprintf(p, p_max_size, "%s", obj->data.s);
4877 new_bg(p, obj->data.l);
4880 new_stippled_hr(p, obj->data.pair.a,
4884 human_readable(cur->swap * 1024, p, 255);
4887 human_readable(cur->swapmax * 1024, p,
4891 if (cur->swapmax == 0) {
4892 strncpy(p, "No swap", 255);
4895 snprintf(p, 255, "%*Lu",
4901 snprintf(p, 4, "%*Lu ",
4909 new_bar(p, obj->data.pair.a,
4911 cur->swapmax ? (cur->swap * 255) /
4912 (cur->swapmax) : 0);
4915 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4918 time_t t = time(NULL);
4919 struct tm *tm = localtime(&t);
4920 setlocale(LC_TIME, "");
4921 strftime(p, p_max_size, obj->data.s, tm);
4924 time_t t = time(NULL);
4925 struct tm *tm = gmtime(&t);
4926 strftime(p, p_max_size, obj->data.s, tm);
4930 if (obj->data.tztime.tz) {
4931 oldTZ = getenv("TZ");
4932 setenv("TZ", obj->data.tztime.tz, 1);
4935 time_t t = time(NULL);
4936 struct tm *tm = localtime(&t);
4937 setlocale(LC_TIME, "");
4938 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4940 setenv("TZ", oldTZ, 1);
4945 // Needless to free oldTZ since getenv gives ptr to static data
4948 human_readable(obj->data.net->recv, p,
4952 human_readable(obj->data.net->trans, p,
4956 snprintf(p, p_max_size, "%d", total_updates);
4960 snprintf(p, p_max_size, "%d",
4961 (int) (obj->data.net->
4965 snprintf(p, 6, "%d ",
4966 (int) (obj->data.net->
4972 snprintf(p, p_max_size, "%.1f",
4974 trans_speed / 1024.0);
4976 snprintf(p, 8, "%.1f ",
4978 trans_speed / 1024.0);
4982 if (obj->data.net->trans_speed == 0)
4983 obj->data.net->trans_speed = 0.01;
4985 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4986 (obj->data.net->trans_speed /
4987 1024.0), obj->e, 1);
4990 format_seconds_short(p, p_max_size,
4994 format_seconds(p, p_max_size, (int) cur->uptime);
4997 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5000 msg = get_apm_adapter();
5001 snprintf(p, p_max_size, "%s", msg);
5004 OBJ(apm_battery_life) {
5006 msg = get_apm_battery_life();
5007 snprintf(p, p_max_size, "%s", msg);
5010 OBJ(apm_battery_time) {
5012 msg = get_apm_battery_time();
5013 snprintf(p, p_max_size, "%s", msg);
5016 #endif /* __FreeBSD__ __OpenBSD__ */
5020 snprintf(p, cur->mpd.max_title_len > 0 ?
5021 cur->mpd.max_title_len : p_max_size, "%s",
5025 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5028 snprintf(p, p_max_size, "%s", cur->mpd.album);
5031 snprintf(p, p_max_size, "%s", cur->mpd.random);
5034 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5037 snprintf(p, p_max_size, "%s", cur->mpd.track);
5040 snprintf(p, p_max_size, "%s", cur->mpd.name);
5043 snprintf(p, p_max_size, "%s", cur->mpd.file);
5046 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5049 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5052 snprintf(p, p_max_size, "%s", cur->mpd.status);
5055 int days = 0, hours = 0, minutes =
5057 int tmp = cur->mpd.elapsed;
5058 while (tmp >= 86400) {
5062 while (tmp >= 3600) {
5072 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
5073 days, hours, minutes,
5076 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5079 snprintf(p, p_max_size, "%i:%02i", minutes,
5083 int days = 0, hours = 0, minutes =
5085 int tmp = cur->mpd.length;
5086 while (tmp >= 86400) {
5090 while (tmp >= 3600) {
5100 snprintf(p, p_max_size,
5101 "%i days %i:%02i:%02i",
5102 days, hours, minutes,
5105 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5108 snprintf(p, p_max_size, "%i:%02i", minutes,
5112 snprintf(p, p_max_size, "%2.0f",
5113 cur->mpd.progress * 100);
5116 new_bar(p, obj->data.pair.a,
5118 (int) (cur->mpd.progress *
5122 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.artist) < 2) {
5123 snprintf(p, p_max_size, "%s", cur->mpd.file);
5125 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
5131 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5134 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5137 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5140 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5142 OBJ(xmms2_comment) {
5143 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5145 OBJ(xmms2_decoder) {
5146 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
5148 OBJ(xmms2_transport) {
5149 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
5152 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5155 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5158 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5160 OBJ(xmms2_tracknr) {
5161 if (cur->xmms2.tracknr != -1)
5162 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5164 OBJ(xmms2_bitrate) {
5165 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5168 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5171 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5173 OBJ(xmms2_elapsed) {
5174 int tmp = cur->xmms2.elapsed;
5175 snprintf(p, p_max_size, "%02d:%02d",
5176 tmp / 60000, (tmp / 1000) % 60);
5178 OBJ(xmms2_duration) {
5179 int tmp = cur->xmms2.duration;
5180 snprintf(p, p_max_size, "%02d:%02d",
5181 tmp / 60000, (tmp / 1000) % 60);
5183 OBJ(xmms2_percent) {
5184 snprintf(p, p_max_size, "%2.0f",
5185 cur->xmms2.progress * 100);
5188 new_bar(p, obj->data.pair.a,
5190 (int) (cur->xmms2.progress *
5194 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
5195 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5197 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
5202 OBJ(audacious_status) {
5203 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
5205 OBJ(audacious_title) {
5206 snprintf(p, cur->audacious.max_title_len > 0 ?
5207 cur->audacious.max_title_len : p_max_size, "%s",
5208 cur->audacious.items[AUDACIOUS_TITLE]);
5210 OBJ(audacious_length) {
5211 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
5213 OBJ(audacious_length_seconds) {
5214 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5216 OBJ(audacious_position) {
5217 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
5219 OBJ(audacious_position_seconds) {
5220 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5222 OBJ(audacious_bitrate) {
5223 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
5225 OBJ(audacious_frequency) {
5226 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
5228 OBJ(audacious_channels) {
5229 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
5231 OBJ(audacious_filename) {
5232 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
5234 OBJ(audacious_playlist_length) {
5235 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5237 OBJ(audacious_playlist_position) {
5238 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5240 OBJ(audacious_bar) {
5242 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5243 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5244 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
5249 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5252 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5255 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5258 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5261 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5264 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5268 if (obj->data.top.type == TOP_NAME
5269 && obj->data.top.num >= 0
5270 && obj->data.top.num < 10) {
5271 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
5272 } else if (obj->data.top.type == TOP_CPU
5273 && obj->data.top.num >= 0
5274 && obj->data.top.num < 10) {
5275 snprintf(p, 7, "%7.3f",
5276 cur->cpu[obj->data.top.
5278 } else if (obj->data.top.type == TOP_PID
5279 && obj->data.top.num >= 0
5280 && obj->data.top.num < 10) {
5281 snprintf(p, 8, "%7i",
5282 cur->cpu[obj->data.top.
5284 } else if (obj->data.top.type == TOP_MEM
5285 && obj->data.top.num >= 0
5286 && obj->data.top.num < 10) {
5287 snprintf(p, 7, "%7.3f",
5288 cur->cpu[obj->data.top.
5293 if (obj->data.top.type == TOP_NAME
5294 && obj->data.top.num >= 0
5295 && obj->data.top.num < 10) {
5296 snprintf(p, 17, "%-17s",
5297 cur->memu[obj->data.top.
5299 } else if (obj->data.top.type == TOP_CPU
5300 && obj->data.top.num >= 0
5301 && obj->data.top.num < 10) {
5302 snprintf(p, 7, "%7.3f",
5303 cur->memu[obj->data.top.
5305 } else if (obj->data.top.type == TOP_PID
5306 && obj->data.top.num >= 0
5307 && obj->data.top.num < 10) {
5308 snprintf(p, 8, "%7i",
5309 cur->memu[obj->data.top.
5311 } else if (obj->data.top.type == TOP_MEM
5312 && obj->data.top.num >= 0
5313 && obj->data.top.num < 10) {
5314 snprintf(p, 7, "%7.3f",
5315 cur->memu[obj->data.top.
5322 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5323 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5325 obj->data.tail.last_update = current_update_time;
5330 if (obj->data.tail.fd != -1) {
5331 tail_pipe(obj, p, p_max_size);
5335 fp = fopen(obj->data.tail.logfile, "rt");
5338 /* Send one message, but do not consistently spam on
5339 * missing logfiles. */
5340 if(obj->data.tail.readlines != 0) {
5341 ERR("tail logfile failed to open");
5342 strcpy(obj->data.tail.buffer, "Logfile Missing");
5344 obj->data.tail.readlines = 0;
5345 snprintf(p, p_max_size, "Logfile Missing");
5348 obj->data.tail.readlines = 0;
5349 /* -1 instead of 0 to avoid counting a trailing newline */
5350 fseek(fp, -1, SEEK_END);
5351 bsize = ftell(fp) + 1;
5352 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5353 nl = rev_fcharfind(fp, '\n', iter);
5357 obj->data.tail.readlines = iter;
5358 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5359 fseek(fp, 0, SEEK_SET);
5362 fseek(fp, nl+1, SEEK_SET);
5365 /* Make sure bsize is at least 1 byte smaller than
5366 * the buffer max size. */
5367 if(bsize > (long)((text_buffer_size*20) - 1)) {
5368 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5369 bsize = text_buffer_size*20 - 1;
5371 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5374 /* Clean up trailing newline, make sure the buffer
5375 * is null terminated. */
5376 if(obj->data.tail.buffer[bsize-1] == '\n')
5377 obj->data.tail.buffer[bsize-1] = '\0';
5379 obj->data.tail.buffer[bsize] = '\0';
5380 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5383 strcpy(obj->data.tail.buffer, "Logfile Empty");
5384 snprintf(p, p_max_size, "Logfile Empty");
5387 } /* if cur_upd_time >= */
5389 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5394 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5395 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5397 obj->data.tail.last_update = current_update_time;
5401 fp = fopen(obj->data.tail.logfile, "rt");
5403 /* Send one message, but do not consistently spam on
5404 * missing logfiles. */
5405 if(obj->data.tail.readlines != 0) {
5406 ERR("head logfile failed to open");
5407 strcpy(obj->data.tail.buffer, "Logfile Missing");
5409 obj->data.tail.readlines = 0;
5410 snprintf(p, p_max_size, "Logfile Missing");
5412 obj->data.tail.readlines = 0;
5413 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5414 nl = fwd_fcharfind(fp, '\n', iter);
5418 obj->data.tail.readlines = iter;
5419 /* Make sure nl is at least 1 byte smaller than
5420 * the buffer max size. */
5421 if(nl > (long)((text_buffer_size*20) - 1)) {
5422 nl = text_buffer_size*20 - 1;
5424 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5427 /* Clean up trailing newline, make sure the buffer
5428 * is null terminated. */
5429 if (obj->data.tail.buffer[nl-1] == '\n') {
5430 obj->data.tail.buffer[nl-1] = '\0';
5433 obj->data.tail.buffer[nl] = '\0';
5435 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5438 strcpy(obj->data.tail.buffer, "Logfile Empty");
5439 snprintf(p, p_max_size, "Logfile Empty");
5441 } /* if fp == null */
5442 } /* cur_upd_time >= */
5444 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5447 #ifdef TCP_PORT_MONITOR
5450 /* grab a pointer to this port monitor */
5451 tcp_port_monitor_t * p_monitor =
5452 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5453 obj->data.tcp_port_monitor.port_range_begin,
5454 obj->data.tcp_port_monitor.port_range_end );
5456 snprintf(p, p_max_size, "monitor not found");
5460 /* now grab the text of interest */
5461 if ( peek_tcp_port_monitor( p_monitor,
5462 obj->data.tcp_port_monitor.item,
5463 obj->data.tcp_port_monitor.connection_index,
5464 p, p_max_size ) != 0 )
5466 snprintf(p, p_max_size, "monitor peek error");
5475 iconv_converting = 1;
5476 iconv_selected = obj->a;
5481 iconv_converting = 0;
5487 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5489 OBJ(entropy_poolsize)
5491 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5495 double entropy_perc;
5496 entropy_perc = (double)cur->entropy.entropy_avail /
5497 (double)cur->entropy.poolsize;
5498 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5506 unsigned int a = strlen(p);
5509 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5511 size_t dummy1, dummy2;
5512 char *ptr = buff_in;
5515 dummy1 = dummy2 = a;
5517 strncpy(buff_in, p, P_MAX_SIZE);
5519 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5520 while (dummy1 > 0) {
5521 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5523 ERR("Iconv codeset conversion failed");
5528 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5539 double current_update_time, last_update_time;
5541 static void generate_text()
5543 struct information *cur = &info;
5551 current_update_time = get_time();
5554 /* fix diskio rates to b/s (use update_interval */
5555 diskio_read_value = diskio_read_value / update_interval;
5556 diskio_write_value = diskio_write_value / update_interval;
5557 diskio_value = diskio_value / update_interval;
5560 /* add things to the buffer */
5566 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5568 if (stuff_in_upper_case) {
5579 last_update_time = current_update_time;
5586 static void set_font()
5590 if (window.xftdraw != NULL) {
5591 XftDrawDestroy(window.xftdraw);
5593 window.xftdraw = XftDrawCreate(display, window.drawable,
5594 DefaultVisual(display,
5596 DefaultColormap(display,
5601 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5607 static inline int get_string_width(const char *s)
5610 return *s ? calc_text_width(s, strlen(s)) : 0;
5616 static inline int get_string_width_special(char *s)
5629 if (*p == SPECIAL_CHAR) {
5630 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5631 for (i = 0; i < strlen(p); i++) {
5632 *(p + i) = *(p + i + 1);
5634 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5635 width += specials[special_index+index].width;
5642 if (strlen(final) > 1) {
5643 width += calc_text_width(final, strlen(final));
5653 static void text_size_updater(char *s);
5655 int last_font_height;
5656 static void update_text_area()
5660 /* update text size if it isn't fixed */
5665 text_width = minimum_width;
5668 last_font_height = font_height();
5669 for_each_line(text_buffer, text_size_updater);
5671 if (text_height < minimum_height)
5672 text_height = minimum_height;
5673 if (text_width > maximum_width && maximum_width > 0)
5674 text_width = maximum_width;
5677 /* get text position on workarea */
5678 switch (text_alignment) {
5685 x = workarea[2] - text_width - gap_x;
5692 y = workarea[3] - text_height - gap_y;
5696 x = workarea[2] - text_width - gap_x;
5697 y = workarea[3] - text_height - gap_y;
5701 case NONE: // Let the WM manage the window
5712 if (own_window && !fixed_pos) {
5715 text_start_x = border_margin + 1;
5716 text_start_y = border_margin + 1;
5717 window.x = x - border_margin - 1;
5718 window.y = y - border_margin - 1;
5722 /* If window size doesn't match to workarea's size, then window
5723 * probably includes panels (gnome).
5724 * Blah, doesn't work on KDE. */
5725 if (workarea[2] != window.width
5726 || workarea[3] != window.height) {
5740 static int cur_x, cur_y; /* current x and y for drawing */
5741 static int draw_mode; /* FG, BG or OUTLINE */
5742 static long current_color;
5745 static void text_size_updater(char *s)
5749 /* get string widths and skip specials */
5752 if (*p == SPECIAL_CHAR) {
5754 w += get_string_width(s);
5757 if (specials[special_index].type == BAR
5758 || specials[special_index].type == GRAPH) {
5759 w += specials[special_index].width;
5760 if (specials[special_index].height > last_font_height) {
5761 last_font_height = specials[special_index].height;
5762 last_font_height += font_ascent();
5764 } else if (specials[special_index].type == OFFSET) {
5765 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5766 } else if (specials[special_index].type == VOFFSET) {
5767 last_font_height += specials[special_index].arg;
5768 } else if (specials[special_index].type == GOTO) {
5769 if (specials[special_index].arg >= 0)
5770 w += (int)specials[special_index].arg - cur_x;
5771 } else if (specials[special_index].type == TAB) {
5772 int start = specials[special_index].arg;
5773 int step = specials[special_index].width;
5774 if (!step || step < 0)
5776 w += step - (cur_x - text_start_x - start) % step;
5777 } else if (specials[special_index].type == FONT) {
5778 selected_font = specials[special_index].font_added;
5779 if (font_height() > last_font_height) {
5780 last_font_height = font_height();
5789 w += get_string_width(s);
5790 if (w > text_width) {
5793 if (text_width > maximum_width && maximum_width) {
5794 text_width = maximum_width;
5797 text_height += last_font_height;
5798 last_font_height = font_height();
5802 static inline void set_foreground_color(long c)
5805 XSetForeground(display, window.gc, c);
5809 static void draw_string(const char *s)
5813 int i, i2, pos, width_of_s;
5816 width_of_s = get_string_width(s);
5817 if (out_to_console) {
5819 fflush(stdout); /* output immediately, don't buffer */
5821 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5822 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5823 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5827 snprintf(space, 2, " ");
5829 max = ((text_width - width_of_s) / get_string_width(space));
5832 * This code looks for tabs in the text and coverts them to spaces.
5833 * The trick is getting the correct number of spaces,
5834 * and not going over the window's size without forcing
5835 * the window larger.
5837 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5838 if (tmpstring1[i] == '\t') // 9 is ascii tab
5842 i2 < (8 - (1 + pos) % 8) && added <= max;
5845 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5846 fprintf(stderr,"buffer overrun detected\n");
5848 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5853 if (tmpstring1[i] != 9) {
5855 if ( pos > TEXT_BUFFER_SIZE-1 )
5856 fprintf(stderr,"buffer overrun detected\n");
5858 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5864 if (text_width == maximum_width) {
5865 /* this means the text is probably pushing the limit, so we'll chop it */
5866 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5867 tmpstring2[strlen(tmpstring2)-1] = '\0';
5877 c.pixel = current_color;
5878 XQueryColor(display, DefaultColormap(display, screen), &c);
5881 c2.color.red = c.red;
5882 c2.color.green = c.green;
5883 c2.color.blue = c.blue;
5884 c2.color.alpha = fonts[selected_font].font_alpha;
5886 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5887 cur_x, cur_y, (XftChar8 *) s,
5890 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5891 cur_x, cur_y, (XftChar8 *) s,
5897 XDrawString(display, window.drawable, window.gc,
5898 cur_x, cur_y, s, strlen(s));
5900 cur_x += width_of_s;
5902 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5905 long redmask, greenmask, bluemask;
5907 void set_up_gradient()
5910 colour_depth = DisplayPlanes(display, screen);
5914 if (colour_depth != 24 && colour_depth != 16) {
5915 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5921 for(i = (colour_depth / 3)-1; i>=0; i--) {
5923 greenmask |= 1 << i;
5926 if (colour_depth%3 == 1) {
5927 greenmask |= 1 << (colour_depth / 3);
5929 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5930 greenmask = greenmask << (colour_depth / 3);
5933 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 */
5935 int red1, green1, blue1; // first colour
5936 int red2, green2, blue2; // second colour
5937 int red3 = 0, green3 = 0, blue3 = 0; // difference
5938 short redshift = (2*colour_depth / 3 + colour_depth%3);
5939 short greenshift = (colour_depth / 3);
5940 red1 = (first_colour & redmask) >> redshift;
5941 green1 = (first_colour & greenmask) >> greenshift;
5942 blue1 = first_colour & bluemask;
5943 red2 = (last_colour & redmask) >> redshift;
5944 green2 = (last_colour & greenmask) >> greenshift;
5945 blue2 = last_colour & bluemask;
5952 if (green1 > green2) {
5955 if (green1 < green2) {
5958 if (blue1 > blue2) {
5961 if (blue1 < blue2) {
5976 if (red1 > bluemask) {
5979 if (green1 > bluemask) {
5982 if (blue1 > bluemask) {
5985 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5989 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5990 if (colour_depth == 0) {
5993 int red1, green1, blue1; // first colour
5994 int red2, green2, blue2; // second colour
5995 long redshift = (2*colour_depth / 3 + colour_depth%3);
5996 long greenshift = (colour_depth / 3);
5997 int red3 = 0, green3 = 0, blue3 = 0; // difference
5998 red1 = (first_colour & redmask) >> redshift;
5999 green1 = (first_colour & greenmask) >> greenshift;
6000 blue1 = first_colour & bluemask;
6001 red2 = (last_colour & redmask) >> redshift;
6002 green2 = (last_colour & greenmask) >> greenshift;
6003 blue2 = last_colour & bluemask;
6004 red3 = abs(red1 - red2);
6005 green3 = abs(green1 - green2);
6006 blue3 = abs(blue1 - blue2);
6015 static void draw_line(char *s)
6019 cur_x = text_start_x;
6020 cur_y += font_ascent();
6022 short font_h = font_height();
6024 /* find specials and draw stuff */
6027 if (*p == SPECIAL_CHAR) {
6030 /* draw string before special */
6037 switch (specials[special_index].type) {
6038 case HORIZONTAL_LINE:
6041 specials[special_index].height;
6042 int mid = font_ascent() / 2;
6043 w = text_start_x + text_width -
6046 XSetLineAttributes(display,
6051 XDrawLine(display, window.drawable,
6062 specials[special_index].height;
6064 specials[special_index].arg;
6065 int mid = font_ascent() / 2;
6066 char ss[2] = { s, s };
6067 w = text_start_x + text_width -
6070 XSetLineAttributes(display,
6075 XSetDashes(display, window.gc, 0,
6077 XDrawLine(display, window.drawable,
6087 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6091 specials[special_index].height;
6093 specials[special_index].arg;
6094 int by = cur_y - (font_ascent() / 2) - 1;
6095 if (h < font_height()) {
6098 w = specials[special_index].width;
6101 text_width - cur_x - 1;
6105 XSetLineAttributes(display,
6111 XDrawRectangle(display,
6115 XFillRectangle(display,
6119 w * bar_usage / 255,
6121 if (specials[special_index].
6123 && specials[special_index].
6127 [special_index].height;
6134 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6138 specials[special_index].height;
6139 unsigned long last_colour = current_color;
6140 int by = cur_y - (font_ascent()/2) - 1;
6141 if (h < font_height()) {
6144 w = specials[special_index].width;
6146 w = text_start_x + text_width - cur_x - 1;
6149 if (draw_graph_borders) {
6150 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
6151 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
6153 XSetLineAttributes(display,
6160 int gradient_size = 0;
6161 float gradient_factor = 0;
6162 float gradient_update = 0;
6163 unsigned long tmpcolour = current_color;
6164 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6165 tmpcolour = specials[special_index].last_colour;
6166 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
6167 gradient_factor = (float)gradient_size / (w - 2);
6169 for (i = w - 2; i > -1; i--) {
6170 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6171 XSetForeground(display, window.gc, tmpcolour);
6172 gradient_update += gradient_factor;
6173 while (gradient_update > 0) {
6174 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
6178 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
6181 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 */
6183 if (specials[special_index].
6185 && specials[special_index].
6189 [special_index].height;
6191 /* if (draw_mode == BG) {
6192 set_foreground_color(default_bg_color);
6194 else if (draw_mode == OUTLINE) {
6195 set_foreground_color(default_out_color);
6197 set_foreground_color(default_fg_color);
6199 set_foreground_color(last_colour);
6205 int old = font_ascent();
6206 cur_y -= font_ascent();
6207 selected_font = specials[special_index].font_added;
6208 if (cur_y + font_ascent() < cur_y + old) {
6211 cur_y += font_ascent();
6217 if (draw_mode == FG)
6218 set_foreground_color(specials
6224 if (draw_mode == BG)
6225 set_foreground_color(specials
6231 if (draw_mode == OUTLINE)
6232 set_foreground_color(specials
6238 w += specials[special_index].arg;
6242 cur_y += specials[special_index].arg;
6246 if (specials[special_index].arg >= 0)
6247 cur_x = (int)specials[special_index].arg;
6252 int start = specials[special_index].arg;
6253 int step = specials[special_index].width;
6254 if (!step || step < 0)
6256 w = step - (cur_x - text_start_x - start) % step;
6262 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
6263 /*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);*/
6264 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6265 cur_x = pos_x - specials[special_index].arg;
6272 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
6273 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
6274 /*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);*/
6276 specials[special_index].arg)
6279 [special_index].arg;
6296 if (cur_y_add > 0) {
6298 cur_y -= font_descent();
6303 cur_y += font_descent();
6307 static void draw_text()
6310 cur_y = text_start_y;
6313 if (draw_borders && border_width > 0) {
6314 unsigned int b = (border_width + 1) / 2;
6316 if (stippled_borders) {
6318 { stippled_borders, stippled_borders };
6319 XSetLineAttributes(display, window.gc,
6320 border_width, LineOnOffDash,
6321 CapButt, JoinMiter);
6322 XSetDashes(display, window.gc, 0, ss, 2);
6324 XSetLineAttributes(display, window.gc,
6325 border_width, LineSolid,
6326 CapButt, JoinMiter);
6329 XDrawRectangle(display, window.drawable, window.gc,
6330 text_start_x - border_margin + b,
6331 text_start_y - border_margin + b,
6332 text_width + border_margin * 2 - 1 - b * 2,
6333 text_height + border_margin * 2 - 1 -
6340 for_each_line(text_buffer, draw_line);
6343 static void draw_stuff()
6347 if (draw_shades && !draw_outline) {
6350 set_foreground_color(default_bg_color);
6360 for (i = -1; i < 2; i++)
6361 for (j = -1; j < 2; j++) {
6362 if (i == 0 && j == 0)
6366 set_foreground_color(default_out_color);
6367 draw_mode = OUTLINE;
6374 set_foreground_color(default_fg_color);
6382 swap.swap_window = window.window;
6383 swap.swap_action = XdbeBackground;
6384 XdbeSwapBuffers(display, &swap, 1);
6390 static void clear_text(int exposures)
6394 return; /* The swap action is XdbeBackground, which clears */
6398 /* there is some extra space for borders and outlines */
6399 XClearArea(display, window.window,
6400 text_start_x - border_margin - 1,
6401 text_start_y - border_margin - 1,
6402 text_width + border_margin * 2 + 2,
6403 text_height + border_margin * 2 + 2,
6404 exposures ? True : 0);
6409 static int need_to_update;
6411 /* update_text() generates new text and clears old text area */
6412 static void update_text()
6421 static void main_loop()
6423 #ifdef SIGNAL_BLOCKING
6424 sigset_t newmask, oldmask;
6426 sigemptyset(&newmask);
6427 sigaddset(&newmask,SIGINT);
6428 sigaddset(&newmask,SIGTERM);
6429 sigaddset(&newmask,SIGUSR1);
6433 Region region = XCreateRegion();
6435 int event_base, error_base;
6436 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6437 ERR("Xdamage extension unavailable");
6439 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6440 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6441 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6442 #endif /* HAVE_XDAMAGE */
6446 while (total_run_times == 0 || info.looped < total_run_times) {
6449 #ifdef SIGNAL_BLOCKING
6450 /* block signals. we will inspect for pending signals later */
6451 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6452 CRIT_ERR("unable to sigprocmask()");
6458 /* wait for X event or timeout */
6460 if (!XPending(display)) {
6465 update_interval - (get_time() -
6471 tv.tv_sec = (long) t;
6472 tv.tv_usec = (long) (t * 1000000) % 1000000;
6474 FD_SET(ConnectionNumber(display), &fdsr);
6477 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6480 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6485 ERR("can't select(): %s",
6496 if (need_to_update) {
6498 int wx = window.x, wy = window.y;
6506 /* resize window if it isn't right size */
6508 (text_width + border_margin * 2 + 1 !=
6510 || text_height + border_margin * 2 + 1 !=
6514 border_margin * 2 + 1;
6517 border_margin * 2 + 1;
6518 XResizeWindow(display,
6523 set_transparent_background(window.window);
6527 /* move window if it isn't in right position */
6530 || window.y != wy)) {
6531 XMoveWindow(display, window.window,
6532 window.x, window.y);
6542 r.x = text_start_x - border_margin;
6543 r.y = text_start_y - border_margin;
6544 r.width = text_width + border_margin * 2;
6545 r.height = text_height + border_margin * 2;
6546 XUnionRectWithRegion(&r, region, region);
6551 /* handle X events */
6553 while (XPending(display)) {
6555 XNextEvent(display, &ev);
6562 r.width = ev.xexpose.width;
6563 r.height = ev.xexpose.height;
6564 XUnionRectWithRegion(&r, region,
6570 case ReparentNotify:
6571 /* set background to ParentRelative for all parents */
6573 set_transparent_background(window.
6578 case ConfigureNotify:
6580 /* if window size isn't what expected, set fixed size */
6581 if (ev.xconfigure.width !=
6583 || ev.xconfigure.height !=
6585 if (window.width != 0
6586 && window.height != 0)
6589 /* clear old stuff before screwing up size and pos */
6595 if (XGetWindowAttributes(display, window.window, &attrs)) {
6610 border_margin * 2 - 1;
6613 border_margin * 2 - 1;
6614 if (text_width > maximum_width && maximum_width > 0)
6615 text_width = maximum_width;
6618 /* if position isn't what expected, set fixed pos, total_updates
6619 * avoids setting fixed_pos when window is set to weird locations
6621 /*if (total_updates >= 2 this is broken
6623 && (window.x != ev.xconfigure.x
6626 && (ev.xconfigure.x != 0
6627 || ev.xconfigure.y != 0)) {
6637 /* if an ordinary window with decorations */
6638 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6640 /* allow conky to hold input focus.*/
6645 /* forward the click to the desktop window */
6646 XUngrabPointer(display, ev.xbutton.time);
6647 ev.xbutton.window = window.desktop;
6648 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6649 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6657 /* if an ordinary window with decorations */
6658 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6660 /* allow conky to hold input focus.*/
6665 /* forward the release to the desktop window */
6666 ev.xbutton.window = window.desktop;
6667 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6676 if (ev.type == event_base + XDamageNotify) {
6677 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6678 XFixesSetRegion(display, part, &dev->area, 1);
6679 XFixesUnionRegion(display, region2, region2, part);
6681 #endif /* HAVE_XDAMAGE */
6686 XDamageSubtract(display, damage, region2, None);
6687 XFixesSetRegion(display, region2, 0, 0);
6688 #endif /* HAVE_XDAMAGE */
6690 /* XDBE doesn't seem to provide a way to clear the back buffer without
6691 * interfering with the front buffer, other than passing XdbeBackground
6692 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6693 * redraw the text even if it wasn't part of the exposed area. OTOH,
6694 * if we're not going to call draw_stuff at all, then no swap happens
6695 * and we can safely do nothing.
6698 if (!XEmptyRegion(region)) {
6702 r.x = text_start_x - border_margin;
6703 r.y = text_start_y - border_margin;
6704 r.width = text_width + border_margin * 2;
6705 r.height = text_height + border_margin * 2;
6706 XUnionRectWithRegion(&r, region, region);
6709 XSetRegion(display, window.gc, region);
6712 XftDrawSetClip(window.xftdraw, region);
6718 XDestroyRegion(region);
6719 region = XCreateRegion();
6723 #ifdef SIGNAL_BLOCKING
6724 /* unblock signals of interest and let handler fly */
6725 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6726 CRIT_ERR("unable to sigprocmask()");
6729 switch(g_signal_pending) {
6732 ERR("received SIGUSR1. reloading the config file.");
6739 ERR("received SIGINT or SIGTERM to terminate. bye!");
6742 XDestroyRegion(region);
6745 return; /* return from main_loop */
6750 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6751 * but didn't write any code to deal with it. if you don't want to
6752 * handle a signal, don't set a handler on it in the first place. */
6753 if (g_signal_pending)
6754 ERR("ignoring signal (%d)", g_signal_pending);
6761 #if defined(X11) && defined(HAVE_XDAMAGE)
6762 XDamageDestroy(display, damage);
6763 XFixesDestroyRegion(display, region2);
6764 XFixesDestroyRegion(display, part);
6765 XDestroyRegion(region);
6767 #endif /* X11 && HAVE_XDAMAGE */
6770 static void load_config_file(const char *);
6772 /* reload the config file */
6773 void reload_config(void)
6775 timed_thread_destroy_registered_threads ();
6777 if (info.cpu_usage) {
6778 free(info.cpu_usage);
6779 info.cpu_usage = NULL;
6788 if (info.mpd.title) {
6789 free(info.mpd.title);
6792 if (info.mpd.artist) {
6793 free(info.mpd.artist);
6794 info.mpd.artist = 0;
6796 if (info.mpd.album) {
6797 free(info.mpd.album);
6800 if (info.mpd.random) {
6801 free(info.mpd.random);
6802 info.mpd.random = 0;
6804 if (info.mpd.repeat) {
6805 free(info.mpd.repeat);
6806 info.mpd.repeat = 0;
6808 if (info.mpd.track) {
6809 free(info.mpd.track);
6812 if (info.mpd.name) {
6813 free(info.mpd.name);
6816 if (info.mpd.file) {
6817 free(info.mpd.file);
6820 if (info.mpd.status) {
6821 free(info.mpd.status);
6822 info.mpd.status = 0;
6830 #ifdef TCP_PORT_MONITOR
6831 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6834 if (current_config) {
6836 load_config_file(current_config);
6838 /* re-init specials array */
6839 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6840 ERR("failed to realloc specials array");
6845 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6848 #ifdef TCP_PORT_MONITOR
6849 info.p_tcp_port_monitor_collection = NULL;
6852 if (create_audacious_thread() !=0)
6853 CRIT_ERR("unable to create audacious thread!");
6854 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6856 extract_variable_text(text);
6865 timed_thread_destroy_registered_threads ();
6867 if (info.cpu_usage) {
6868 free(info.cpu_usage);
6869 info.cpu_usage = NULL;
6874 XdbeDeallocateBackBufferName(display, window.back_buffer);
6880 XDestroyWindow(display, window.window);
6881 XClearWindow(display, RootWindow(display, screen));
6887 XClearWindow(display, RootWindow(display, screen));
6892 XFreeGC(display, window.gc);
6896 free_text_objects(text_object_count, text_objects);
6897 text_object_count = 0;
6898 text_objects = NULL;
6900 if (text != original_text)
6903 free(current_config);
6905 #ifdef TCP_PORT_MONITOR
6906 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6907 info.p_tcp_port_monitor_collection = NULL;
6915 for(i=0;i<special_count;i++)
6916 if(specials[i].type == GRAPH)
6917 free(specials[i].graph);
6923 static int string_to_bool(const char *s)
6927 if (strcasecmp(s, "yes") == 0)
6929 if (strcasecmp(s, "true") == 0)
6931 if (strcasecmp(s, "1") == 0)
6936 static enum alignment string_to_alignment(const char *s)
6938 if (strcasecmp(s, "top_left") == 0)
6940 else if (strcasecmp(s, "top_right") == 0)
6942 else if (strcasecmp(s, "bottom_left") == 0)
6944 else if (strcasecmp(s, "bottom_right") == 0)
6945 return BOTTOM_RIGHT;
6946 else if (strcasecmp(s, "tl") == 0)
6948 else if (strcasecmp(s, "tr") == 0)
6950 else if (strcasecmp(s, "bl") == 0)
6952 else if (strcasecmp(s, "br") == 0)
6953 return BOTTOM_RIGHT;
6954 else if (strcasecmp(s, "none") == 0)
6961 static void set_default_configurations(void)
6963 fork_to_background = 0;
6964 total_run_times = 0;
6965 info.cpu_avg_samples = 2;
6966 info.net_avg_samples = 2;
6971 strcpy(info.mpd.host, "localhost");
6972 info.mpd.port = 6600;
6973 info.mpd.status = NULL;
6974 info.mpd.artist = NULL;
6975 info.mpd.album = NULL;
6976 info.mpd.title = NULL;
6977 info.mpd.random = NULL;
6978 info.mpd.track = NULL;
6979 info.mpd.name = NULL;
6980 info.mpd.file = NULL;
6983 info.xmms2.artist = NULL;
6984 info.xmms2.album = NULL;
6985 info.xmms2.title = NULL;
6986 info.xmms2.genre = NULL;
6987 info.xmms2.comment = NULL;
6988 info.xmms2.decoder = NULL;
6989 info.xmms2.transport = NULL;
6990 info.xmms2.url = NULL;
6991 info.xmms2.status = NULL;
7000 default_fg_color = WhitePixel(display, screen);
7001 default_bg_color = BlackPixel(display, screen);
7002 default_out_color = BlackPixel(display, screen);
7003 color0 = default_fg_color;
7004 color1 = default_fg_color;
7005 color2 = default_fg_color;
7006 color3 = default_fg_color;
7007 color4 = default_fg_color;
7008 color5 = default_fg_color;
7009 color6 = default_fg_color;
7010 color7 = default_fg_color;
7011 color8 = default_fg_color;
7012 color9 = default_fg_color;
7015 draw_graph_borders = 1;
7017 set_first_font("6x10");
7025 window.type=TYPE_NORMAL;
7027 strcpy(window.class_name, "Conky");
7029 sprintf(window.title,"%s - conky",info.uname_s.nodename);
7031 stippled_borders = 0;
7034 text_alignment = BOTTOM_LEFT;
7037 free(current_mail_spool);
7040 variable_substitute(MAIL_FILE, buf, 256);
7042 current_mail_spool = strdup(buf);
7046 update_interval = 3.0;
7047 info.music_player_interval = 1.0;
7048 stuff_in_upper_case = 0;
7050 #ifdef TCP_PORT_MONITOR
7051 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7055 static void load_config_file(const char *f)
7057 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7061 set_default_configurations();
7067 char buf[256], *p, *p2, *name, *value;
7069 if (fgets(buf, 256, fp) == NULL)
7074 /* break at comment */
7075 p2 = strchr(p, '#');
7080 while (*p && isspace((int) *p))
7083 continue; /* empty line */
7089 while (*p2 && !isspace((int) *p2))
7092 *p2 = '\0'; /* break at name's end */
7099 while (*p && isspace((int) *p))
7104 p2 = value + strlen(value);
7105 while (isspace((int) *(p2 - 1)))
7111 #define CONF2(a) if (strcasecmp(name, a) == 0)
7112 #define CONF(a) else CONF2(a)
7113 #define CONF3(a,b) \
7114 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
7118 CONF2("alignment") {
7120 int a = string_to_alignment(value);
7128 CONF("background") {
7129 fork_to_background = string_to_bool(value);
7133 CONF2("background") {
7134 fork_to_background = string_to_bool(value);
7138 CONF("border_margin") {
7140 border_margin = strtol(value, 0, 0);
7144 CONF("border_width") {
7146 border_width = strtol(value, 0, 0);
7152 color0 = get_x11_color(value);
7158 color1 = get_x11_color(value);
7164 color2 = get_x11_color(value);
7170 color3 = get_x11_color(value);
7176 color4 = get_x11_color(value);
7182 color5 = get_x11_color(value);
7188 color6 = get_x11_color(value);
7194 color7 = get_x11_color(value);
7200 color8 = get_x11_color(value);
7206 color9 = get_x11_color(value);
7210 CONF("default_color") {
7212 default_fg_color = get_x11_color(value);
7216 CONF3("default_shade_color", "default_shadecolor") {
7218 default_bg_color = get_x11_color(value);
7222 CONF3("default_outline_color", "default_outlinecolor") {
7224 default_out_color = get_x11_color(value);
7231 info.mail = parse_mail_args(IMAP, value);
7238 info.mail = parse_mail_args(POP3, value);
7246 strncpy(info.mpd.host, value, 127);
7252 info.mpd.port = strtol(value, 0, 0);
7253 if (info.mpd.port < 1
7254 || info.mpd.port > 0xffff)
7258 CONF("mpd_password") {
7260 strncpy(info.mpd.password, value, 127);
7265 CONF("music_player_interval") {
7267 info.music_player_interval = strtod(value, 0);
7272 CONF("sensor_device") {
7274 sensor_device = strtol(value, 0, 0);
7279 CONF("cpu_avg_samples") {
7281 cpu_avg_samples = strtol(value, 0, 0);
7282 if (cpu_avg_samples < 1
7283 || cpu_avg_samples > 14)
7292 CONF("net_avg_samples") {
7294 net_avg_samples = strtol(value, 0, 0);
7295 if (net_avg_samples < 1
7296 || net_avg_samples > 14)
7312 CONF("double_buffer") {
7313 use_xdbe = string_to_bool(value);
7317 CONF("override_utf8_locale") {
7318 utf8_mode = string_to_bool(value);
7321 CONF("draw_borders") {
7322 draw_borders = string_to_bool(value);
7324 CONF("draw_graph_borders") {
7325 draw_graph_borders = string_to_bool(value);
7327 CONF("draw_shades") {
7328 draw_shades = string_to_bool(value);
7330 CONF("draw_outline") {
7331 draw_outline = string_to_bool(value);
7334 CONF("out_to_console") {
7335 out_to_console = string_to_bool(value);
7337 CONF("use_spacer") {
7338 use_spacer = string_to_bool(value);
7343 use_xft = string_to_bool(value);
7347 set_first_font(value);
7352 if (value && font_count >= 0)
7353 fonts[0].font_alpha = atof(value)
7362 if (string_to_bool(value))
7363 ERR("Xft not enabled");
7366 /* xftfont silently ignored when no Xft */
7369 /* xftalpha is silently ignored when no Xft */
7374 set_first_font(value);
7383 gap_x = atoi(value);
7389 gap_y = atoi(value);
7394 CONF("mail_spool") {
7397 variable_substitute(value, buf, 256);
7401 if (current_mail_spool)
7402 free(current_mail_spool);
7403 current_mail_spool = strdup(buf);
7409 CONF("minimum_size") {
7412 (value, "%d %d", &minimum_width,
7413 &minimum_height) != 2)
7416 &minimum_width) != 1)
7421 CONF("maximum_width") {
7423 if (sscanf(value, "%d", &maximum_width) != 1)
7429 CONF("no_buffers") {
7430 no_buffers = string_to_bool(value);
7432 CONF("pad_percents") {
7433 pad_percents = atoi(value);
7437 CONF("own_window") {
7439 own_window = string_to_bool(value);
7443 CONF("own_window_class") {
7446 memset(window.class_name,0,sizeof(window.class_name));
7447 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7452 CONF("own_window_title") {
7455 memset(window.title,0,sizeof(window.title));
7456 strncpy(window.title, value, sizeof(window.title)-1);
7461 CONF("own_window_transparent") {
7463 set_transparent = string_to_bool(value);
7467 CONF("own_window_colour") {
7469 background_colour = get_x11_color(value);
7471 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7474 CONF("own_window_hints") {
7476 char *p_hint, *p_save;
7477 char delim[] = ", ";
7479 /* tokenize the value into individual hints */
7480 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7482 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7483 if (strncmp(p_hint,"undecorate",10) == 0)
7484 SET_HINT(window.hints,HINT_UNDECORATED);
7485 else if (strncmp(p_hint,"below",5) == 0)
7486 SET_HINT(window.hints,HINT_BELOW);
7487 else if (strncmp(p_hint,"above",5) == 0)
7488 SET_HINT(window.hints,HINT_ABOVE);
7489 else if (strncmp(p_hint,"sticky",6) == 0)
7490 SET_HINT(window.hints,HINT_STICKY);
7491 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7492 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7493 else if (strncmp(p_hint,"skip_pager",10) == 0)
7494 SET_HINT(window.hints,HINT_SKIP_PAGER);
7498 p_hint=strtok_r(NULL, delim, &p_save);
7500 while (p_hint!=NULL);
7505 CONF("own_window_type") {
7507 if (strncmp(value,"normal",6)==0)
7508 window.type = TYPE_NORMAL;
7509 else if (strncmp(value,"desktop",7)==0)
7510 window.type = TYPE_DESKTOP;
7511 else if (strncmp(value,"override",8)==0)
7512 window.type = TYPE_OVERRIDE;
7520 CONF("stippled_borders") {
7522 stippled_borders = strtol(value, 0, 0);
7524 stippled_borders = 4;
7528 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7531 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7533 CONF("update_interval") {
7535 update_interval = strtod(value, 0);
7538 if (info.music_player_interval == 0) {
7539 // default to update_interval
7540 info.music_player_interval = update_interval;
7543 CONF("total_run_times") {
7545 total_run_times = strtod(value, 0);
7550 stuff_in_upper_case = string_to_bool(value);
7552 CONF("max_specials") {
7554 max_specials = atoi(value);
7558 CONF("max_user_text") {
7560 max_user_text = atoi(value);
7564 CONF("text_buffer_size") {
7566 text_buffer_size = atoi(value);
7571 if (text != original_text)
7581 int l = strlen(text);
7582 if (fgets(buf, 256, fp) == NULL)
7585 realloc(text, l + strlen(buf)
7589 if (strlen(text) > max_user_text)
7593 text_lines = line + 1;
7596 #ifdef TCP_PORT_MONITOR
7597 CONF("max_port_monitor_connections")
7600 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7601 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7603 /* an error. use default, warn and continue. */
7604 tcp_port_monitor_args.max_port_monitor_connections =
7605 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7608 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7610 /* no error, just use default */
7611 tcp_port_monitor_args.max_port_monitor_connections =
7612 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7614 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7619 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7628 if (info.music_player_interval == 0) {
7629 // default to update_interval
7630 info.music_player_interval = update_interval;
7635 /* : means that character before that takes an argument */
7636 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7649 int main(int argc, char **argv)
7651 struct sigaction act, oact;
7654 memset(&info, 0, sizeof(info));
7656 #ifdef TCP_PORT_MONITOR
7657 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7660 /* handle command line parameters that don't change configs */
7665 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7666 *s) || ((s = getenv("LANG")) && *s)) {
7667 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7669 ERR("malloc failed");
7671 for (x = 0; x < strlen(s); x++) {
7672 temp[x] = tolower(s[x]);
7675 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7681 if (!setlocale(LC_CTYPE, "")) {
7682 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7686 int c = getopt(argc,
7697 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7698 * though free() does the NULL check itself;), then load optarg value */
7700 free(current_config);
7701 current_config = strdup(optarg);
7706 ("Usage: %s [OPTION]...\n"
7707 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7708 "window. Command line options will override configurations defined in config\n"
7711 " -c FILE config file to load instead of "
7714 " -d daemonize, fork to background\n"
7717 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7718 " -f FONT font to use\n"
7720 " -o create own window to draw\n"
7723 " -b double buffer (prevents flickering)\n"
7725 " -w WIN_ID window id to draw\n"
7726 " -x X x position\n"
7727 " -y Y y position\n"
7729 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7730 " -u SECS update interval\n"
7731 " -i NUM number of times to update Conky\n", argv[0]);
7735 window.window = strtol(optarg, 0, 0);
7744 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7748 /* load current_config or CONFIG_FILE */
7751 if (current_config == NULL) {
7752 /* load default config file */
7755 variable_substitute(CONFIG_FILE, buf, 256);
7758 current_config = strdup(buf);
7762 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7763 load_config_file(current_config);
7765 set_default_configurations();
7768 /* init specials array */
7769 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7770 ERR("failed to create specials array");
7773 if (current_mail_spool == NULL) {
7775 variable_substitute(MAIL_FILE, buf, 256);
7778 current_mail_spool = strdup(buf);
7782 /* handle other command line arguments */
7784 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7785 optind = optreset = 1;
7790 #if defined(__FreeBSD__)
7791 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7792 O_RDONLY, "kvm_open")) == NULL)
7793 CRIT_ERR( "cannot read kvm");
7797 int c = getopt(argc,
7805 fork_to_background = 1;
7810 set_first_font(optarg);
7813 text_alignment = string_to_alignment(optarg);
7828 if (text != original_text)
7830 text = strdup(optarg);
7831 convert_escapes(text);
7835 update_interval = strtod(optarg, 0);
7836 if (info.music_player_interval == 0) {
7837 // default to update_interval
7838 info.music_player_interval = update_interval;
7843 total_run_times = strtod(optarg, 0);
7847 gap_x = atoi(optarg);
7851 gap_y = atoi(optarg);
7865 /* generate text and get initial size */
7866 extract_variable_text(text);
7867 if (text != original_text) {
7872 if (fork_to_background) {
7876 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7882 fprintf(stderr,"\n"); fflush(stderr);
7886 /* parent process */
7887 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7894 update_text_area(); /* to get initial size of the window */
7898 text_width + border_margin * 2 + 1,
7899 text_height + border_margin * 2 + 1,
7900 set_transparent, background_colour, argv, argc);
7903 update_text_area(); /* to position text/window on screen */
7908 if (own_window && !fixed_pos) {
7909 XMoveWindow(display, window.window, window.x, window.y);
7912 set_transparent_background(window.window);
7923 /* Set signal handlers */
7924 act.sa_handler = signal_handler;
7925 sigemptyset(&act.sa_mask);
7928 act.sa_flags |= SA_RESTART;
7931 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7932 sigaction(SIGUSR1,&act,&oact) < 0 ||
7933 sigaction(SIGTERM,&act,&oact) < 0 )
7935 ERR("error setting signal handler: %s", strerror(errno) );
7939 if (create_audacious_thread() !=0)
7940 CRIT_ERR("unable to create audacious thread!");
7941 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7952 #if defined(__FreeBSD__)
7959 void signal_handler(int sig)
7961 /* signal handler is light as a feather, as it should be.
7962 * we will poll g_signal_pending with each loop of conky
7963 * and do any signal processing there, NOT here. */
7964 g_signal_pending=sig;