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>
66 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
69 #define CONFIG_FILE "$HOME/.conkyrc"
70 #define MAIL_FILE "$MAIL"
71 #define MAX_IF_BLOCK_DEPTH 5
73 /* #define SIGNAL_BLOCKING */
74 #undef SIGNAL_BLOCKING
76 static void print_version()
78 printf("Conky %s compiled %s for %s\n",
79 VERSION, BUILD_DATE, BUILD_ARCH);
82 "\nCompiled in features:\n\n"
86 " * Xdamage extension\n"
87 # endif /* HAVE_XDAMAGE */
89 " * Xdbe extension (double buffer)\n"
90 # endif /* HAVE_XDBE */
96 "\n Music detection:\n"
99 #endif /* AUDACIOUS */
109 "\n General features:\n"
113 #ifdef TCP_PORT_MONITOR
115 #endif /* TCP_PORT_MONITOR */
133 static int text_start_x, text_start_y; /* text start position in window */
134 static int text_width, text_height;
149 char name[TEXT_BUFFER_SIZE];
159 static int selected_font = 0;
160 static int font_count = -1;
161 struct font_list *fonts = NULL;
165 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
166 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
167 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
168 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
172 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
173 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
174 #define font_descent() fonts[selected_font].font->max_bounds.descent
178 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
181 static void set_font();
183 int addfont(const char *data_in)
185 if (font_count > MAX_FONTS) {
186 CRIT_ERR("you don't need that many fonts, sorry.");
189 if (font_count == 0) {
193 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
197 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
199 CRIT_ERR("realloc in addfont");
201 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
202 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
204 fonts[font_count].font_alpha = 0xffff;
207 CRIT_ERR("Oops...looks like something overflowed in addfont().");
212 void set_first_font(const char *data_in)
214 if (font_count < 0) {
215 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
220 if (strlen(data_in) > 1) {
221 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
223 fonts[0].font_alpha = 0xffff;
231 for (i = 0; i <= font_count; i++) {
234 XftFontClose(display, fonts[i].xftfont);
238 XFreeFont(display, fonts[i].font);
248 static void load_fonts()
251 for (i=0; i <= font_count; i++) {
255 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
256 XftFontClose(display, fonts[i].xftfont);
258 if ((fonts[i].xftfont =
259 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
262 ERR("can't load Xft font '%s'", fonts[i].name);
263 if ((fonts[i].xftfont =
264 XftFontOpenName(display, screen,
265 "courier-12")) != NULL)
268 ERR("can't load Xft font '%s'", "courier-12");
270 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
271 CRIT_ERR("can't load font '%s'", "fixed");
278 /* load normal font */
279 /* if (fonts[i].font != NULL)
280 XFreeFont(display, fonts[i].font);*/
282 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
283 ERR("can't load font '%s'", fonts[i].name);
284 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
285 CRIT_ERR("can't load font '%s'", "fixed");
286 printf("loaded fixed?\n");
294 /* default config file */
295 static char *current_config;
297 /* set to 1 if you want all text to be in uppercase */
298 static unsigned int stuff_in_upper_case;
300 /* Run how many times? */
301 static unsigned long total_run_times;
304 static int fork_to_background;
306 static int cpu_avg_samples, net_avg_samples;
310 /* Position on the screen */
311 static int text_alignment;
312 static int gap_x, gap_y;
315 static int draw_borders;
316 static int draw_graph_borders;
317 static int stippled_borders;
319 static int draw_shades, draw_outline;
321 static int border_margin, border_width;
323 static long default_fg_color, default_bg_color, default_out_color;
325 /* create own window or draw stuff to root? */
326 static int set_transparent = 0;
330 static int own_window = 0;
331 static int background_colour = 0;
332 /* fixed size/pos is set if wm/user changes them */
333 static int fixed_size = 0, fixed_pos = 0;
336 static int minimum_width, minimum_height;
337 static int maximum_width;
342 static int sensor_device;
345 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
347 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
348 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
350 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
351 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
353 /* maximum size of individual text buffers, ie $exec buffer size */
354 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
357 #define CODEPAGE_LENGTH 20
359 long iconv_count = 0;
360 char iconv_converting;
361 static iconv_t **iconv_cd = 0;
363 int register_iconv(iconv_t *new_iconv)
366 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
368 iconv_cd = malloc(sizeof(iconv_t *));
371 CRIT_ERR("Out of memory");
373 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
374 if (!iconv_cd[iconv_count]) {
375 CRIT_ERR("Out of memory");
377 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
382 void free_iconv(void)
386 for (i = 0; i < iconv_count; i++) {
388 iconv_close(*iconv_cd[i]);
403 /* no buffers in used memory? */
406 /* pad percentages to decimals? */
407 static int pad_percents = 0;
409 #ifdef TCP_PORT_MONITOR
410 tcp_port_monitor_args_t tcp_port_monitor_args;
413 /* Text that is shown */
414 static char original_text[] =
415 "$nodename - $sysname $kernel on $machine\n"
417 "${color grey}Uptime:$color $uptime\n"
418 "${color grey}Frequency (in MHz):$color $freq\n"
419 "${color grey}Frequency (in GHz):$color $freq_g\n"
420 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
421 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
422 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
423 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
425 "${color grey}File systems:\n"
426 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
427 "${color grey}Networking:\n"
428 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
431 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
432 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
435 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
436 "Progress: $xmms2_bar\n"
438 "${color grey}Name PID CPU% MEM%\n"
439 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
440 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
441 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
442 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
443 "${tail /var/log/Xorg.0.log 3}";
445 static char *text = original_text;
448 static int total_updates;
451 static int blockdepth = 0;
452 static int if_jumped = 0;
453 static int blockstart[MAX_IF_BLOCK_DEPTH];
455 int check_contains(char *f, char *s)
458 FILE *where = fopen(f, "r");
460 char buf1[256], buf2[256];
461 while (fgets(buf1, 256, where)) {
462 sscanf(buf1, "%255s", buf2);
463 if (strstr(buf2, s)) {
470 ERR("Could not open the file");
477 static inline int calc_text_width(const char *s, int l)
483 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
485 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
491 return XTextWidth(fonts[selected_font].font, s, l);
496 /* formatted text to render on screen, generated in generate_text(),
497 * drawn in draw_stuff() */
499 static char text_buffer[TEXT_BUFFER_SIZE * 4];
501 /* special stuff in text_buffer */
503 #define SPECIAL_CHAR '\x01'
532 unsigned long first_colour; // for graph gradient
533 unsigned long last_colour;
536 /* create specials array on heap instead of stack with introduction of max_specials */
537 static struct special_t *specials = NULL;
539 static unsigned int special_count;
541 static unsigned int special_index; /* used when drawing */
544 #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? */
546 static struct special_t *new_special(char *buf, int t)
548 if (special_count >= max_specials)
549 CRIT_ERR("too many special things in text");
551 buf[0] = SPECIAL_CHAR;
553 specials[special_count].type = t;
554 return &specials[special_count++];
557 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
560 unsigned int count = 0;
561 static char buf[BUFSZ];
562 long orig_pos = ftell(fp);
564 long buf_size = BUFSZ;
565 char* cur_found = NULL;
566 while(count < step) {
567 if(cur_found == NULL) {
568 buf_size = fread(buf, 1, buf_size, fp);
571 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
572 if(cur_found != NULL) {
573 buf_pos = cur_found-buf+1;
582 ret = ftell(fp) - buf_size + buf_pos - 1;
583 fseek(fp, orig_pos, SEEK_SET);
590 memrchr (const void *buffer, int c, size_t n)
592 const unsigned char *p = buffer;
594 for (p += n; n ; n--)
600 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
603 unsigned int count = 0;
604 static char buf[BUFSZ];
605 long orig_pos = ftell(fp);
607 long file_pos = orig_pos;
608 long buf_size = BUFSZ;
610 while(count < step) {
612 if(file_pos > BUFSZ) {
613 fseek(fp, file_pos-BUFSZ, SEEK_SET);
617 fseek(fp, 0, SEEK_SET);
619 file_pos = ftell(fp);
620 buf_pos = fread(buf, 1, buf_size, fp);
627 if(cur_found != NULL) {
628 buf_pos = cur_found-buf;
637 fseek(fp, orig_pos, SEEK_SET);
639 ret = file_pos + buf_pos;
644 static void new_bar(char *buf, int w, int h, int usage)
646 struct special_t *s = new_special(buf, BAR);
647 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
652 static const char *scan_bar(const char *args, int *w, int *h)
654 *w = 0; /* zero width means all space that is available */
656 /* bar's argument is either height or height,width */
659 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
660 sscanf(args, "%d %n", h, &n);
667 static char *scan_font(const char *args)
676 static void new_font(char *buf, char * args) {
678 struct special_t *s = new_special(buf, FONT);
679 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
680 int tmp = selected_font;
681 selected_font = s->font_added = addfont(args);
686 struct special_t *s = new_special(buf, FONT);
687 int tmp = selected_font;
688 selected_font = s->font_added = 0;
694 inline void graph_append(struct special_t *graph, double f)
696 if (!graph->scaled && f > graph->graph_scale) {
697 f = graph->graph_scale;
701 graph->graph_scale = 1;
703 graph->graph[0] = f; /* add new data */
704 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
705 graph->graph[i] = graph->graph[i - 1];
706 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
707 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
712 short colour_depth = 0;
713 void set_up_gradient();
715 /* precalculated: 31/255, and 63/255 */
716 #define CONST_8_TO_5_BITS 0.12156862745098
717 #define CONST_8_TO_6_BITS 0.247058823529412
719 /* adjust color values depending on color depth*/
720 static unsigned int adjust_colors(unsigned int color)
723 if (colour_depth == 0) {
726 if (colour_depth == 16) {
727 r = (color & 0xff0000) >> 16;
728 g = (color & 0xff00) >> 8;
730 color = (int)(r * CONST_8_TO_5_BITS) << 11;
731 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
732 color |= (int)(b * CONST_8_TO_5_BITS);
737 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
739 struct special_t *s = new_special(buf, GRAPH);
741 if (s->graph == NULL) {
742 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
743 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
745 s->graph_width = MAX_GRAPH_DEPTH - 2;
747 s->graph = malloc(s->graph_width * sizeof(double));
748 memset(s->graph, 0, s->graph_width * sizeof(double));
749 s->graph_scale = 100;
752 s->first_colour = adjust_colors(first_colour);
753 s->last_colour = adjust_colors(second_colour);
760 s->graph_width = s->width - 2; // subtract 2 for rectangle around
765 s->graph_scale = scale;
772 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
774 *w = 0; /* zero width means all space that is available */
778 /* graph's argument is either height or height,width */
780 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
781 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
783 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
785 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
788 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
792 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
795 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
799 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
802 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
806 if (sscanf(args, "%d,%d", h, w) < 2) {
809 sscanf(args, "%*s %d,%d", h, w);
815 static inline void new_hr(char *buf, int a)
817 new_special(buf, HORIZONTAL_LINE)->height = a;
820 static inline void new_stippled_hr(char *buf, int a, int b)
822 struct special_t *s = new_special(buf, STIPPLED_HR);
827 static inline void new_fg(char *buf, long c)
829 new_special(buf, FG)->arg = c;
832 static inline void new_bg(char *buf, long c)
834 new_special(buf, BG)->arg = c;
837 static inline void new_outline(char *buf, long c)
839 new_special(buf, OUTLINE)->arg = c;
842 static inline void new_offset(char *buf, long c)
844 new_special(buf, OFFSET)->arg = c;
847 static inline void new_voffset(char *buf, long c)
849 new_special(buf, VOFFSET)->arg = c;
852 static inline void new_alignr(char *buf, long c)
854 new_special(buf, ALIGNR)->arg = c;
857 static inline void new_alignc(char *buf, long c)
859 new_special(buf, ALIGNC)->arg = c;
862 static inline void new_goto(char *buf, long c)
864 new_special(buf, GOTO)->arg = c;
867 static inline void new_tab(char *buf, int a, int b) {
868 struct special_t *s = new_special(buf, TAB);
873 /* quite boring functions */
875 static inline void for_each_line(char *b, void (*f) (char *))
879 for (ps = b, pe = b; *pe; pe++) {
892 static void convert_escapes(char *buf)
894 char *p = buf, *s = buf;
910 /* converts from bytes to human readable format (k, M, G, T) */
911 static void human_readable(long long a, char *buf, int size)
913 // Strange conditional due to possible overflows
914 if(a / 1024 / 1024 / 1024.0 > 1024.0){
915 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
917 else if (a >= 1024 * 1024 * 1024) {
918 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
920 else if (a >= 1024 * 1024) {
921 double m = (a / 1024) / 1024.0;
923 snprintf(buf, size, "%.0fMiB", m);
925 snprintf(buf, size, "%.1fMiB", m);
926 } else if (a >= 1024)
927 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
929 snprintf(buf, size, "%LdB", a);
934 enum text_object_type {
947 #endif /* !__OpenBSD__ */
969 OBJ_diskiograph_read,
970 OBJ_diskiograph_write,
1005 #if defined(__linux__)
1011 OBJ_i8k_left_fan_status,
1012 OBJ_i8k_right_fan_status,
1013 OBJ_i8k_left_fan_rpm,
1014 OBJ_i8k_right_fan_rpm,
1016 OBJ_i8k_buttons_status,
1026 OBJ_wireless_bitrate,
1028 OBJ_wireless_link_qual,
1029 OBJ_wireless_link_qual_max,
1030 OBJ_wireless_link_qual_perc,
1031 OBJ_wireless_link_bar,
1032 #endif /* __linux__ */
1061 OBJ_running_processes,
1070 OBJ_temp1, /* i2c is used instead in these */
1090 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1092 OBJ_apm_battery_time,
1093 OBJ_apm_battery_life,
1094 #endif /* __FreeBSD__ __OpenBSD__ */
1096 OBJ_obsd_sensors_temp,
1097 OBJ_obsd_sensors_fan,
1098 OBJ_obsd_sensors_volt,
1101 #endif /* __OpenBSD__ */
1123 OBJ_music_player_interval,
1131 OBJ_xmms2_transport,
1146 OBJ_audacious_status,
1147 OBJ_audacious_title,
1148 OBJ_audacious_length,
1149 OBJ_audacious_length_seconds,
1150 OBJ_audacious_position,
1151 OBJ_audacious_position_seconds,
1152 OBJ_audacious_bitrate,
1153 OBJ_audacious_frequency,
1154 OBJ_audacious_channels,
1155 OBJ_audacious_filename,
1156 OBJ_audacious_playlist_length,
1157 OBJ_audacious_playlist_position,
1171 #ifdef TCP_PORT_MONITOR
1182 OBJ_entropy_poolsize,
1186 struct text_object {
1190 unsigned int c, d, e;
1194 char *s; /* some string */
1195 int i; /* some integer */
1196 long l; /* some other integer */
1197 unsigned int sensor;
1198 struct net_stat *net;
1200 unsigned char loadavg[3];
1201 unsigned int cpu_index;
1202 struct mail_s *mail;
1210 char *tz; /* timezone variable */
1211 char *fmt; /* time display formatting */
1264 timed_thread *p_timed_thread;
1270 #ifdef TCP_PORT_MONITOR
1272 in_port_t port_range_begin; /* starting port to monitor */
1273 in_port_t port_range_end; /* ending port to monitor */
1274 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1275 int connection_index; /* 0 to n-1 connections. */
1296 struct text_object_list {
1297 unsigned int text_object_count;
1298 struct text_object *text_objects;
1301 static unsigned int text_object_count;
1302 static struct text_object *text_objects;
1303 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1305 #define MAXDATASIZE 1000
1309 struct mail_s* parse_mail_args(char type, const char *arg) {
1310 struct mail_s *mail;
1311 mail = malloc(sizeof(struct mail_s));
1312 memset(mail, 0, sizeof(struct mail_s));
1314 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1316 ERR("Scanning IMAP args failed");
1317 } else if (type == IMAP) {
1318 ERR("Scanning POP3 args failed");
1321 // see if password needs prompting
1322 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1323 int fp = fileno(stdin);
1324 struct termios term;
1325 tcgetattr(fp, &term);
1326 term.c_lflag &= ~ECHO;
1327 tcsetattr(fp, TCSANOW, &term);
1328 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1329 scanf("%128s", mail->pass);
1331 term.c_lflag |= ECHO;
1332 tcsetattr(fp, TCSANOW, &term);
1334 // now we check for optional args
1335 tmp = strstr(arg, "-i ");
1338 sscanf(tmp, "%f", &mail->interval);
1340 mail->interval = 300; // 5 minutes
1342 tmp = strstr(arg, "-p ");
1345 sscanf(tmp, "%lu", &mail->port);
1348 mail->port = 110; // default pop3 port
1349 } else if (type == IMAP) {
1350 mail->port = 143; // default imap port
1354 tmp = strstr(arg, "-f ");
1357 sscanf(tmp, "%s", mail->folder);
1359 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1362 tmp = strstr(arg, "-e ");
1366 if (tmp[0] == '\'') {
1367 len = strstr(tmp+1, "'") - tmp - 1;
1372 strncpy(mail->command, tmp+1, len);
1374 mail->command[0] = '\0';
1376 mail->p_timed_thread = NULL;
1380 void *imap_thread(struct mail_s* mail)
1382 int sockfd, numbytes;
1383 char recvbuf[MAXDATASIZE];
1384 char sendbuf[MAXDATASIZE];
1387 unsigned int old_unseen = UINT_MAX;
1388 unsigned int old_messages = UINT_MAX;
1389 struct stat stat_buf;
1391 struct sockaddr_in their_addr; // connector's address information
1392 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1393 herror("gethostbyname");
1398 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1400 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1403 goto next_iteration;
1406 their_addr.sin_family = AF_INET; // host byte order
1407 their_addr.sin_port = htons(mail->port); // short, network byte order
1408 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1409 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1412 (sockfd, (struct sockaddr *) &their_addr,
1413 sizeof(struct sockaddr)) == -1) {
1416 goto next_iteration;
1418 struct timeval timeout;
1421 timeout.tv_sec = 60; // 60 second timeout i guess
1422 timeout.tv_usec = 0;
1424 FD_SET(sockfd, &fdset);
1425 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1428 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1432 goto next_iteration;
1435 ERR("IMAP connection failed: timeout");
1437 goto next_iteration;
1439 recvbuf[numbytes] = '\0';
1440 if (strstr(recvbuf, "* OK") != recvbuf) {
1441 ERR("IMAP connection failed, probably not an IMAP server");
1443 goto next_iteration;
1445 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1446 strncat(sendbuf, mail->user,
1447 MAXDATASIZE - strlen(sendbuf) - 1);
1448 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1449 strncat(sendbuf, mail->pass,
1450 MAXDATASIZE - strlen(sendbuf) - 1);
1451 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1452 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1455 goto next_iteration;
1457 timeout.tv_sec = 60; // 60 second timeout i guess
1458 timeout.tv_usec = 0;
1460 FD_SET(sockfd, &fdset);
1461 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1464 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1468 goto next_iteration;
1471 recvbuf[numbytes] = '\0';
1472 if (strstr(recvbuf, "a1 OK") == NULL) {
1473 ERR("IMAP server login failed: %s", recvbuf);
1475 goto next_iteration;
1477 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1478 strncat(sendbuf, mail->folder,
1479 MAXDATASIZE - strlen(sendbuf) - 1);
1480 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1481 MAXDATASIZE - strlen(sendbuf) - 1);
1482 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1485 goto next_iteration;
1487 timeout.tv_sec = 60; // 60 second timeout i guess
1488 timeout.tv_usec = 0;
1490 FD_SET(sockfd, &fdset);
1491 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1494 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1498 goto next_iteration;
1501 recvbuf[numbytes] = '\0';
1502 if (strstr(recvbuf, "a2 OK") == NULL) {
1503 ERR("IMAP status failed: %s", recvbuf);
1505 goto next_iteration;
1507 // now we get the data
1508 reply = strstr(recvbuf, " (MESSAGES ");
1510 *strchr(reply, ')') = '\0';
1511 if (reply == NULL) {
1512 ERR("Error parsing IMAP response: %s", recvbuf);
1514 goto next_iteration;
1516 timed_thread_lock (mail->p_timed_thread);
1517 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1520 timed_thread_unlock (mail->p_timed_thread);
1522 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1523 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1526 goto next_iteration;
1528 timeout.tv_sec = 60; // 60 second timeout i guess
1529 timeout.tv_usec = 0;
1531 FD_SET(sockfd, &fdset);
1532 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1535 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1539 goto next_iteration;
1542 recvbuf[numbytes] = '\0';
1543 if (strstr(recvbuf, "a3 OK") == NULL) {
1544 ERR("IMAP logout failed: %s", recvbuf);
1546 goto next_iteration;
1548 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1549 if (system(mail->command) == -1) {
1554 old_unseen = mail->unseen;
1555 old_messages = mail->messages;
1557 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1558 /* if a valid socket, close it */
1560 if (timed_thread_test (mail->p_timed_thread))
1561 timed_thread_exit (mail->p_timed_thread);
1568 void *pop3_thread(struct mail_s *mail)
1570 int sockfd, numbytes;
1571 char recvbuf[MAXDATASIZE];
1572 char sendbuf[MAXDATASIZE];
1575 unsigned int old_unseen = UINT_MAX;
1576 struct stat stat_buf;
1578 struct sockaddr_in their_addr; // connector's address information
1579 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1580 herror("gethostbyname");
1585 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1587 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1590 goto next_iteration;
1593 their_addr.sin_family = AF_INET; // host byte order
1594 their_addr.sin_port = htons(mail->port); // short, network byte order
1595 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1596 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1599 (sockfd, (struct sockaddr *) &their_addr,
1600 sizeof(struct sockaddr)) == -1) {
1603 goto next_iteration;
1605 struct timeval timeout;
1608 timeout.tv_sec = 60; // 60 second timeout i guess
1609 timeout.tv_usec = 0;
1611 FD_SET(sockfd, &fdset);
1612 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1615 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1619 goto next_iteration;
1622 ERR("POP3 connection failed: timeout\n");
1624 goto next_iteration;
1626 recvbuf[numbytes] = '\0';
1627 if (strstr(recvbuf, "+OK ") != recvbuf) {
1628 ERR("POP3 connection failed, probably not a POP3 server");
1630 goto next_iteration;
1632 strncpy(sendbuf, "USER ", MAXDATASIZE);
1633 strncat(sendbuf, mail->user,
1634 MAXDATASIZE - strlen(sendbuf) - 1);
1635 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1636 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1637 perror("send USER");
1639 goto next_iteration;
1641 timeout.tv_sec = 60; // 60 second timeout i guess
1642 timeout.tv_usec = 0;
1644 FD_SET(sockfd, &fdset);
1645 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1648 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1650 perror("recv USER");
1652 goto next_iteration;
1655 recvbuf[numbytes] = '\0';
1656 if (strstr(recvbuf, "+OK ") == NULL) {
1657 ERR("POP3 server login failed: %s", recvbuf);
1659 goto next_iteration;
1661 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1662 strncat(sendbuf, mail->pass,
1663 MAXDATASIZE - strlen(sendbuf) - 1);
1664 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1665 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1666 perror("send PASS");
1668 goto next_iteration;
1670 timeout.tv_sec = 60; // 60 second timeout i guess
1671 timeout.tv_usec = 0;
1673 FD_SET(sockfd, &fdset);
1674 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1677 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1679 perror("recv PASS");
1681 goto next_iteration;
1684 recvbuf[numbytes] = '\0';
1685 if (strstr(recvbuf, "+OK ") == NULL) {
1686 ERR("POP3 server login failed: %s", recvbuf);
1688 goto next_iteration;
1690 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1691 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1692 perror("send STAT");
1694 goto next_iteration;
1696 timeout.tv_sec = 60; // 60 second timeout i guess
1697 timeout.tv_usec = 0;
1699 FD_SET(sockfd, &fdset);
1700 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1703 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1705 perror("recv STAT");
1707 goto next_iteration;
1710 recvbuf[numbytes] = '\0';
1711 if (strstr(recvbuf, "+OK ") == NULL) {
1712 ERR("POP3 status failed: %s", recvbuf);
1714 goto next_iteration;
1716 // now we get the data
1717 reply = recvbuf + 4;
1718 if (reply == NULL) {
1719 ERR("Error parsing POP3 response: %s", recvbuf);
1721 goto next_iteration;
1723 timed_thread_lock (mail->p_timed_thread);
1724 sscanf(reply, "%lu %lu", &mail->unseen,
1726 timed_thread_unlock (mail->p_timed_thread);
1728 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1729 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1730 perror("send QUIT");
1732 goto next_iteration;
1734 timeout.tv_sec = 60; // 60 second timeout i guess
1735 timeout.tv_usec = 0;
1737 FD_SET(sockfd, &fdset);
1738 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1741 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1743 perror("recv QUIT");
1745 goto next_iteration;
1748 recvbuf[numbytes] = '\0';
1749 if (strstr(recvbuf, "+OK") == NULL) {
1750 ERR("POP3 logout failed: %s", recvbuf);
1752 goto next_iteration;
1754 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1755 if (system(mail->command) == -1) {
1760 old_unseen = mail->unseen;
1762 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1763 /* if a valid socket, close it */
1765 if (timed_thread_test (mail->p_timed_thread))
1766 timed_thread_exit (mail->p_timed_thread);
1774 void *threaded_exec(struct text_object *obj) {
1776 char *p2 = obj->data.texeci.buffer;
1777 FILE *fp = popen(obj->data.texeci.cmd,"r");
1778 timed_thread_lock (obj->data.texeci.p_timed_thread);
1779 int n2 = fread(p2, 1, text_buffer_size, fp);
1782 if (n2 && p2[n2 - 1] == '\n') {
1786 if (*p2 == '\001') {
1791 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1792 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1793 timed_thread_exit (obj->data.texeci.p_timed_thread);
1798 static struct text_object *new_text_object_internal()
1800 struct text_object *obj = malloc(sizeof(struct text_object));
1801 memset(obj, 0, sizeof(struct text_object));
1805 static void free_text_objects(unsigned int count, struct text_object *objs)
1808 for (i = 0; i < count; i++) {
1809 switch (objs[i].type) {
1812 close(objs[i].data.i);
1815 close(objs[i].data.i);
1818 close(objs[i].data.sysfs.fd);
1821 close(objs[i].data.sysfs.fd);
1824 close(objs[i].data.sysfs.fd);
1826 #endif /* !__OpenBSD__ */
1828 free(objs[i].data.s);
1831 free(objs[i].data.s);
1834 free(objs[i].data.tztime.tz);
1835 free(objs[i].data.tztime.fmt);
1838 free(objs[i].data.mboxscan.args);
1839 free(objs[i].data.mboxscan.output);
1844 case OBJ_imap_unseen:
1845 if (!objs[i].global_mode) {
1846 free(objs[i].data.mail);
1849 case OBJ_imap_messages:
1850 if (!objs[i].global_mode) {
1851 free(objs[i].data.mail);
1857 case OBJ_pop3_unseen:
1858 if (!objs[i].global_mode) {
1859 free(objs[i].data.mail);
1863 if (!objs[i].global_mode) {
1864 free(objs[i].data.mail);
1868 case OBJ_if_existing:
1869 case OBJ_if_mounted:
1870 case OBJ_if_running:
1871 free(objs[i].data.ifblock.s);
1872 free(objs[i].data.ifblock.str);
1875 free(objs[i].data.tail.logfile);
1876 free(objs[i].data.tail.buffer);
1880 free(objs[i].data.s);
1883 free(objs[i].data.s);
1886 free(objs[i].data.s);
1889 free(objs[i].data.s);
1892 free(objs[i].data.s);
1894 /* case OBJ_execibar:
1895 free(objs[i].data.s);
1897 case OBJ_execigraph:
1898 free(objs[i].data.s);
1901 case OBJ_iconv_start:
1906 case OBJ_xmms2_artist:
1907 if (info.xmms2.artist) {
1908 free(info.xmms2.artist);
1909 info.xmms2.artist = 0;
1912 case OBJ_xmms2_album:
1913 if (info.xmms2.album) {
1914 free(info.xmms2.album);
1915 info.xmms2.album = 0;
1918 case OBJ_xmms2_title:
1919 if (info.xmms2.title) {
1920 free(info.xmms2.title);
1921 info.xmms2.title = 0;
1924 case OBJ_xmms2_genre:
1925 if (info.xmms2.genre) {
1926 free(info.xmms2.genre);
1927 info.xmms2.genre = 0;
1930 case OBJ_xmms2_comment:
1931 if (info.xmms2.comment) {
1932 free(info.xmms2.comment);
1933 info.xmms2.comment = 0;
1936 case OBJ_xmms2_decoder:
1937 if (info.xmms2.decoder) {
1938 free(info.xmms2.decoder);
1942 case OBJ_xmms2_transport:
1943 if (info.xmms2.transport) {
1944 free(info.xmms2.transport);
1949 if (info.xmms2.url) {
1950 free(info.xmms2.url);
1954 case OBJ_xmms2_date:
1955 if (info.xmms2.date) {
1956 free(info.xmms2.date);
1957 info.xmms2.date = 0;
1960 case OBJ_xmms2_status:
1961 if (info.xmms2.status) {
1962 free(info.xmms2.status);
1963 info.xmms2.status = 0;
1966 case OBJ_xmms2_smart:
1967 if (info.xmms2.artist) {
1968 free(info.xmms2.artist);
1969 info.xmms2.artist = 0;
1971 if (info.xmms2.title) {
1972 free(info.xmms2.title);
1973 info.xmms2.title = 0;
1975 if (info.xmms2.url) {
1976 free(info.xmms2.url);
1982 case OBJ_bmpx_title:
1983 case OBJ_bmpx_artist:
1984 case OBJ_bmpx_album:
1985 case OBJ_bmpx_track:
1987 case OBJ_bmpx_bitrate:
1991 free(objs[i].data.rss.uri);
1992 free(objs[i].data.rss.action);
1998 free(objs[i].data.s);
2000 case OBJ_battery_time:
2001 free(objs[i].data.s);
2003 #endif /* !__OpenBSD__ */
2005 free(objs[i].data.execi.cmd);
2006 free(objs[i].data.execi.buffer);
2009 free(objs[i].data.texeci.cmd);
2010 free(objs[i].data.texeci.buffer);
2013 if (info.first_process) {
2014 free_all_processes();
2015 info.first_process = NULL;
2019 if (info.first_process) {
2020 free_all_processes();
2021 info.first_process = NULL;
2026 free(objs[i].data.hddtemp.dev);
2027 free(objs[i].data.hddtemp.addr);
2030 case OBJ_entropy_avail:
2031 case OBJ_entropy_poolsize:
2032 case OBJ_entropy_bar:
2039 if (info.mpd.title) {
2040 free(info.mpd.title);
2043 if (info.mpd.artist) {
2044 free(info.mpd.artist);
2045 info.mpd.artist = 0;
2047 if (info.mpd.album) {
2048 free(info.mpd.album);
2051 if (info.mpd.random) {
2052 free(info.mpd.random);
2053 info.mpd.random = 0;
2055 if (info.mpd.repeat) {
2056 free(info.mpd.repeat);
2057 info.mpd.repeat = 0;
2059 if (info.mpd.track) {
2060 free(info.mpd.track);
2063 if (info.mpd.name) {
2064 free(info.mpd.name);
2067 if (info.mpd.file) {
2068 free(info.mpd.file);
2071 if (info.mpd.status) {
2072 free(info.mpd.status);
2073 info.mpd.status = 0;
2077 //text_objects = NULL;
2078 //text_object_count = 0;
2081 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2086 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2087 *a = mixer_init(buf1);
2088 (void) scan_bar(arg + n, w, h);
2091 (void) scan_bar(arg, w, h);
2096 /* construct_text_object() creates a new text_object */
2097 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2099 //struct text_object *obj = new_text_object();
2100 struct text_object *obj = new_text_object_internal();
2103 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2104 #define END ; } } else
2108 obj->type = OBJ_color;
2109 obj->data.l = get_x11_color(s);
2113 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2114 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2115 END OBJ(acpiacadapter, 0)
2116 #endif /* !__OpenBSD__ */
2118 OBJ(freq, INFO_FREQ)
2120 END OBJ(freq, INFO_FREQ)
2127 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2129 obj->data.cpu_index=1;
2130 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2134 obj->data.cpu_index=atoi(&arg[0]);
2137 END OBJ(freq_g, INFO_FREQ)
2143 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2145 obj->data.cpu_index=1;
2146 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2150 obj->data.cpu_index=atoi(&arg[0]);
2153 #if defined(__linux__)
2154 END OBJ(voltage_mv, 0)
2160 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2162 obj->data.cpu_index=1;
2163 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2167 obj->data.cpu_index=atoi(&arg[0]);
2170 END OBJ(voltage_v, 0)
2176 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2178 obj->data.cpu_index=1;
2179 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2183 obj->data.cpu_index=atoi(&arg[0]);
2188 END OBJ(wireless_essid, INFO_NET)
2190 obj->data.net = get_net_stat(arg);
2192 CRIT_ERR("wireless_essid: needs an argument");
2193 END OBJ(wireless_mode, INFO_NET)
2195 obj->data.net = get_net_stat(arg);
2197 CRIT_ERR("wireless_mode: needs an argument");
2198 END OBJ(wireless_bitrate, INFO_NET)
2200 obj->data.net = get_net_stat(arg);
2202 CRIT_ERR("wireless_bitrate: needs an argument");
2203 END OBJ(wireless_ap, INFO_NET)
2205 obj->data.net = get_net_stat(arg);
2207 CRIT_ERR("wireless_ap: needs an argument");
2208 END OBJ(wireless_link_qual, INFO_NET)
2210 obj->data.net = get_net_stat(arg);
2212 CRIT_ERR("wireless_link_qual: needs an argument");
2213 END OBJ(wireless_link_qual_max, INFO_NET)
2215 obj->data.net = get_net_stat(arg);
2217 CRIT_ERR("wireless_link_qual_max: needs an argument");
2218 END OBJ(wireless_link_qual_perc, INFO_NET)
2220 obj->data.net = get_net_stat(arg);
2222 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2223 END OBJ(wireless_link_bar, INFO_NET)
2225 arg = scan_bar(arg, &obj->a, &obj->b);
2226 obj->data.net = get_net_stat(arg);
2228 CRIT_ERR("wireless_link_bar: needs an argument");
2229 #endif /* HAVE_IWLIB */
2231 #endif /* __linux__ */
2232 END OBJ(freq_dyn, 0);
2233 END OBJ(freq_dyn_g, 0);
2235 END OBJ(acpifan, 0);
2236 END OBJ(battery, 0);
2239 sscanf(arg, "%63s", bat);
2241 strcpy(bat, "BAT0");
2242 obj->data.s = strdup(bat);
2243 END OBJ(battery_time, 0);
2246 sscanf(arg, "%63s", bat);
2248 strcpy(bat, "BAT0");
2249 obj->data.s = strdup(bat);
2250 END OBJ(battery_percent, 0);
2253 sscanf(arg, "%63s", bat);
2255 strcpy(bat, "BAT0");
2256 obj->data.s = strdup(bat);
2257 END OBJ(battery_bar, 0);
2260 arg = scan_bar(arg, &obj->a, &obj->b);
2261 sscanf(arg, "%63s", bat);
2263 strcpy(bat, "BAT0");
2265 obj->data.s = strdup(bat);
2266 #endif /* !__OpenBSD__ */
2267 #if defined(__linux__)
2268 END OBJ(i8k_version, INFO_I8K)
2269 END OBJ(i8k_bios, INFO_I8K)
2270 END OBJ(i8k_serial, INFO_I8K)
2271 END OBJ(i8k_cpu_temp, INFO_I8K)
2272 END OBJ(i8k_cpu_tempf, INFO_I8K)
2273 END OBJ(i8k_left_fan_status, INFO_I8K)
2274 END OBJ(i8k_right_fan_status, INFO_I8K)
2275 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2276 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2277 END OBJ(i8k_ac_status, INFO_I8K)
2278 END OBJ(i8k_buttons_status, INFO_I8K)
2280 END OBJ(ibm_temps, 0)
2282 CRIT_ERR("ibm_temps: needs an argument");
2284 if (!isdigit(arg[0])
2286 || atoi(&arg[0]) >=8)
2289 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2291 obj->data.sensor = atoi(&arg[0]);
2292 END OBJ(ibm_volume, 0)
2293 END OBJ(ibm_brightness, 0)
2294 END OBJ(pb_battery, 0)
2295 if (arg && strcmp(arg, "status") == 0) {
2296 obj->data.i = PB_BATT_STATUS;
2297 } else if (arg && strcmp(arg, "percent") == 0) {
2298 obj->data.i = PB_BATT_PERCENT;
2299 } else if (arg && strcmp(arg, "time") == 0) {
2300 obj->data.i = PB_BATT_TIME;
2302 ERR("pb_battery: needs one argument: status, percent or time");
2307 #endif /* __linux__ */
2308 #if defined(__OpenBSD__)
2309 END OBJ(obsd_sensors_temp, 0);
2311 CRIT_ERR("obsd_sensors_temp: needs an argument");
2313 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2315 ERR("Invalid temperature sensor number!");
2317 obj->data.sensor = atoi(&arg[0]);
2318 END OBJ(obsd_sensors_fan, 0);
2320 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2322 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2324 ERR("Invalid fan sensor number!");
2326 obj->data.sensor = atoi(&arg[0]);
2327 END OBJ(obsd_sensors_volt, 0);
2329 CRIT_ERR("obsd_sensors_volt: 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 voltage sensor number!");
2335 obj->data.sensor = atoi(&arg[0]);
2336 END OBJ(obsd_vendor, 0);
2337 END OBJ(obsd_product, 0);
2338 #endif /* __OpenBSD__ */
2339 END OBJ(buffers, INFO_BUFFERS)
2340 END OBJ(cached, INFO_BUFFERS)
2341 END OBJ(cpu, INFO_CPU)
2343 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2344 obj->data.cpu_index = atoi(&arg[3]);
2346 } else {obj->data.cpu_index = 0; }
2348 obj->data.cpu_index = 0;
2350 END OBJ(cpubar, INFO_CPU)
2352 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2353 obj->data.cpu_index = atoi(&arg[3]);
2356 else {obj->data.cpu_index = 0;}
2357 (void) scan_bar(arg, &obj->a, &obj->b);
2359 (void) scan_bar(arg, &obj->a, &obj->b);
2360 obj->data.cpu_index = 0;
2362 END OBJ(cpugraph, INFO_CPU)
2364 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2365 obj->data.cpu_index = atoi(&arg[3]);
2368 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2370 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2371 obj->data.cpu_index = 0;
2373 END OBJ(diskio, INFO_DISKIO)
2374 END OBJ(diskio_read, INFO_DISKIO)
2375 END OBJ(diskio_write, INFO_DISKIO)
2376 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2377 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2378 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2381 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2384 obj->data.l = color0;
2386 obj->data.l = color1;
2388 obj->data.l = color2;
2390 obj->data.l = color3;
2392 obj->data.l = color4;
2394 obj->data.l = color5;
2396 obj->data.l = color6;
2398 obj->data.l = color7;
2400 obj->data.l = color8;
2402 obj->data.l = color9;
2404 obj->data.s = scan_font(arg);
2405 END OBJ(downspeed, INFO_NET)
2407 obj->data.net = get_net_stat(arg);
2410 CRIT_ERR("downspeed needs argument");
2412 END OBJ(downspeedf, INFO_NET)
2414 obj->data.net = get_net_stat(arg);
2417 CRIT_ERR("downspeedf needs argument");
2419 END OBJ(downspeedgraph, INFO_NET)
2420 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2422 sscanf(arg, "%63s %*i,%*i %*i", buf);
2423 obj->data.net = get_net_stat(buf);
2424 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2425 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2432 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2433 blockstart[blockdepth - 1] = object_count;
2434 obj->data.ifblock.pos = object_count + 2;
2436 ERR("$else: no matching $if_*");
2441 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2443 ERR("$endif: no matching $if_*");
2446 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2449 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2450 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2451 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2452 END OBJ(execibar, 0) unsigned int n;
2453 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2455 ERR("${execibar <interval> command}");
2456 obj->type = OBJ_text;
2457 snprintf(buf, 256, "${%s}", s);
2458 obj->data.s = strdup(buf);
2460 obj->data.execi.cmd = strdup(arg + n);
2462 END OBJ(execigraph, 0) unsigned int n;
2463 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2465 ERR("${execigraph <interval> command}");
2466 obj->type = OBJ_text;
2467 snprintf(buf, 256, "${%s}", s);
2468 obj->data.s = strdup(buf);
2470 obj->data.execi.cmd = strdup(arg + n);
2472 END OBJ(execi, 0) unsigned int n;
2473 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2475 ERR("${execi <interval> command}");
2476 obj->type = OBJ_text;
2477 snprintf(buf, 256, "${%s}", s);
2478 obj->data.s = strdup(buf);
2480 obj->data.execi.cmd = strdup(arg + n);
2481 obj->data.execi.buffer =
2482 (char *) calloc(1, text_buffer_size);
2484 END OBJ(texeci, 0) unsigned int n;
2485 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2487 ERR("${texeci <interval> command}");
2488 obj->type = OBJ_text;
2489 snprintf(buf, 256, "${%s}", s);
2490 obj->data.s = strdup(buf);
2492 obj->data.texeci.cmd = strdup(arg + n);
2493 obj->data.texeci.buffer =
2494 (char *) calloc(1, text_buffer_size);
2496 obj->data.texeci.p_timed_thread = NULL;
2497 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2499 FILE *fp = popen(arg, "r");
2503 n = fread(buf, 1, 2048, fp);
2506 if (n && buf[n - 1] == '\n')
2511 obj->data.s = strdup(buf);
2513 obj->data.s = strdup("");
2516 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2517 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2519 while (isspace(*arg))
2525 obj->data.fsbar.fs = prepare_fs_stat(arg);
2526 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2529 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2533 obj->data.fsbar.fs = prepare_fs_stat(arg);
2534 END OBJ(fs_free, INFO_FS) if (!arg)
2536 obj->data.fs = prepare_fs_stat(arg);
2537 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2539 obj->data.fs = prepare_fs_stat(arg);
2540 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2542 obj->data.fs = prepare_fs_stat(arg);
2543 END OBJ(fs_size, INFO_FS) if (!arg)
2545 obj->data.fs = prepare_fs_stat(arg);
2546 END OBJ(fs_used, INFO_FS) if (!arg)
2548 obj->data.fs = prepare_fs_stat(arg);
2549 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2550 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2551 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2555 ERR("goto needs arguments");
2556 obj->type = OBJ_text;
2557 obj->data.s = strdup("${goto}");
2561 obj->data.i = atoi(arg);
2566 if (sscanf(arg, "%d %d", &a, &b) != 2)
2567 sscanf(arg, "%d", &b);
2571 obj->data.pair.a = a;
2572 obj->data.pair.b = b;
2575 END OBJ(i2c, INFO_SYSFS)
2576 char buf1[64], buf2[64];
2580 ERR("i2c needs arguments");
2581 obj->type = OBJ_text;
2582 //obj->data.s = strdup("${i2c}");
2586 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2587 /* if scanf couldn't read three values, read type and num and use default device */
2588 sscanf(arg, "%63s %d", buf2, &n);
2589 obj->data.sysfs.fd =
2590 open_i2c_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2591 strncpy(obj->data.sysfs.type, buf2, 63);
2593 obj->data.sysfs.fd =
2594 open_i2c_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2595 strncpy(obj->data.sysfs.type, buf2, 63);
2598 END OBJ(platform, INFO_SYSFS)
2599 char buf1[64], buf2[64];
2603 ERR("platform needs arguments");
2604 obj->type = OBJ_text;
2608 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2609 /* if scanf couldn't read three values, read type and num and use default device */
2610 sscanf(arg, "%63s %d", buf2, &n);
2611 obj->data.sysfs.fd =
2612 open_platform_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2613 strncpy(obj->data.sysfs.type, buf2, 63);
2615 obj->data.sysfs.fd =
2616 open_platform_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2617 strncpy(obj->data.sysfs.type, buf2, 63);
2620 END OBJ(hwmon, INFO_SYSFS)
2621 char buf1[64], buf2[64];
2625 ERR("hwmon needs argumanets");
2626 obj->type = OBJ_text;
2630 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2631 /* if scanf couldn't read three values, read type and num and use default device */
2632 sscanf(arg, "%63s %d", buf2, &n);
2633 obj->data.sysfs.fd =
2634 open_hwmon_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2635 strncpy(obj->data.sysfs.type, buf2, 63);
2637 obj->data.sysfs.fd =
2638 open_hwmon_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2639 strncpy(obj->data.sysfs.type, buf2, 63);
2641 #endif /* !__OpenBSD__ */
2643 END OBJ(top, INFO_TOP)
2647 ERR("top needs arguments");
2648 obj->type = OBJ_text;
2649 //obj->data.s = strdup("${top}");
2652 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2653 if (strcmp(buf, "name") == 0) {
2654 obj->data.top.type = TOP_NAME;
2655 } else if (strcmp(buf, "cpu") == 0) {
2656 obj->data.top.type = TOP_CPU;
2657 } else if (strcmp(buf, "pid") == 0) {
2658 obj->data.top.type = TOP_PID;
2659 } else if (strcmp(buf, "mem") == 0) {
2660 obj->data.top.type = TOP_MEM;
2662 ERR("invalid arg for top");
2665 if (n < 1 || n > 10) {
2666 CRIT_ERR("invalid arg for top");
2669 obj->data.top.num = n - 1;
2673 ERR("invalid args given for top");
2676 END OBJ(top_mem, INFO_TOP)
2680 ERR("top_mem needs arguments");
2681 obj->type = OBJ_text;
2682 obj->data.s = strdup("${top_mem}");
2685 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2686 if (strcmp(buf, "name") == 0) {
2687 obj->data.top.type = TOP_NAME;
2688 } else if (strcmp(buf, "cpu") == 0) {
2689 obj->data.top.type = TOP_CPU;
2690 } else if (strcmp(buf, "pid") == 0) {
2691 obj->data.top.type = TOP_PID;
2692 } else if (strcmp(buf, "mem") == 0) {
2693 obj->data.top.type = TOP_MEM;
2695 ERR("invalid arg for top");
2698 if (n < 1 || n > 10) {
2699 CRIT_ERR("invalid arg for top");
2702 obj->data.top.num = n - 1;
2706 ERR("invalid args given for top");
2709 END OBJ(addr, INFO_NET)
2711 obj->data.net = get_net_stat(arg);
2714 CRIT_ERR("addr needs argument");
2720 ERR("tail needs arguments");
2721 obj->type = OBJ_text;
2722 obj->data.s = strdup("${tail}");
2725 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2726 if (n1 < 1 || n1 > 30) {
2727 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2731 fp = fopen(buf, "r");
2733 obj->data.tail.logfile =
2734 malloc(text_buffer_size);
2735 strcpy(obj->data.tail.logfile, buf);
2736 obj->data.tail.wantedlines = n1;
2737 obj->data.tail.interval =
2738 update_interval * 2;
2742 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2745 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2746 if (n1 < 1 || n1 > 30) {
2748 ("invalid arg for tail, number of lines must be between 1 and 30");
2750 } else if (n2 < 1 || n2 < update_interval) {
2752 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2756 fp = fopen(buf, "r");
2758 obj->data.tail.logfile =
2759 malloc(text_buffer_size);
2760 strcpy(obj->data.tail.logfile, buf);
2761 obj->data.tail.wantedlines = n1;
2762 obj->data.tail.interval = n2;
2766 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2772 ERR("invalid args given for tail");
2775 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2780 ERR("head needs arguments");
2781 obj->type = OBJ_text;
2782 obj->data.s = strdup("${head}");
2785 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2786 if (n1 < 1 || n1 > 30) {
2787 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2791 fp = fopen(buf, "r");
2793 obj->data.tail.logfile =
2794 malloc(text_buffer_size);
2795 strcpy(obj->data.tail.logfile, buf);
2796 obj->data.tail.wantedlines = n1;
2797 obj->data.tail.interval =
2798 update_interval * 2;
2802 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2805 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2806 if (n1 < 1 || n1 > 30) {
2808 ("invalid arg for head, number of lines must be between 1 and 30");
2810 } else if (n2 < 1 || n2 < update_interval) {
2812 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2816 fp = fopen(buf, "r");
2818 obj->data.tail.logfile =
2819 malloc(text_buffer_size);
2820 strcpy(obj->data.tail.logfile, buf);
2821 obj->data.tail.wantedlines = n1;
2822 obj->data.tail.interval = n2;
2826 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2832 ERR("invalid args given for head");
2835 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2836 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2838 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2839 if (r >= 3 && (c < 1 || c > 3))
2841 if (r >= 2 && (b < 1 || b > 3))
2843 if (r >= 1 && (a < 1 || a > 3))
2846 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2847 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2848 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2849 END OBJ(if_empty, 0)
2850 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2851 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2854 ERR("if_empty needs an argument");
2855 obj->data.ifblock.s = 0;
2857 obj->data.ifblock.s = strdup(arg);
2858 blockstart[blockdepth] = object_count;
2859 obj->data.ifblock.pos = object_count + 2;
2861 END OBJ(if_existing, 0)
2862 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2863 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2866 ERR("if_existing needs an argument or two");
2867 obj->data.ifblock.s = NULL;
2868 obj->data.ifblock.str = NULL;
2870 char buf1[256], buf2[256];
2871 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2873 obj->data.ifblock.s = strdup(buf1);
2874 obj->data.ifblock.str = NULL;
2876 obj->data.ifblock.s = strdup(buf1);
2877 obj->data.ifblock.str = strdup(buf2);
2880 blockstart[blockdepth] = object_count;
2881 obj->data.ifblock.pos = object_count + 2;
2883 END OBJ(if_mounted, 0)
2884 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2885 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2888 ERR("if_mounted needs an argument");
2889 obj->data.ifblock.s = 0;
2891 obj->data.ifblock.s = strdup(arg);
2892 blockstart[blockdepth] = object_count;
2893 obj->data.ifblock.pos = object_count + 2;
2895 END OBJ(if_running, 0)
2896 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2897 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2901 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2902 obj->data.ifblock.s = strdup(buf);
2904 ERR("if_running needs an argument");
2905 obj->data.ifblock.s = 0;
2907 blockstart[blockdepth] = object_count;
2908 obj->data.ifblock.pos = object_count + 2;
2912 END OBJ(mails, INFO_MAIL)
2913 END OBJ(mboxscan, 0)
2914 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2915 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2916 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2917 obj->data.mboxscan.output[0] = 1;
2918 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2919 END OBJ(mem, INFO_MEM)
2920 END OBJ(memmax, INFO_MEM)
2921 END OBJ(memperc, INFO_MEM)
2922 END OBJ(membar, INFO_MEM)
2923 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2924 END OBJ(memgraph, INFO_MEM)
2925 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2926 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2927 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2928 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2929 END OBJ(mixerbar, INFO_MIXER)
2930 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2931 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2932 END OBJ(mixerlbar, INFO_MIXER)
2933 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2934 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2935 END OBJ(mixerrbar, INFO_MIXER)
2936 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2937 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2939 OBJ(new_mails, INFO_MAIL)
2940 END OBJ(nodename, 0)
2941 END OBJ(processes, INFO_PROCS)
2942 END OBJ(running_processes, INFO_RUN_PROCS)
2943 END OBJ(shadecolor, 0)
2945 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2947 END OBJ(outlinecolor, 0)
2949 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2951 END OBJ(stippled_hr, 0)
2953 int a = stippled_borders, b = 1;
2955 if (sscanf(arg, "%d %d", &a, &b) != 2)
2956 sscanf(arg, "%d", &b);
2960 obj->data.pair.a = a;
2961 obj->data.pair.b = b;
2963 END OBJ(swap, INFO_MEM)
2964 END OBJ(swapmax, INFO_MEM)
2965 END OBJ(swapperc, INFO_MEM)
2966 END OBJ(swapbar, INFO_MEM)
2967 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2970 END OBJ(temp1, INFO_SYSFS) obj->type = OBJ_i2c;
2971 obj->data.sysfs.fd =
2972 open_i2c_sensor(0, "temp", 1, &obj->data.sysfs.arg,
2973 obj->data.sysfs.devtype);
2974 END OBJ(temp2, INFO_SYSFS) obj->type = OBJ_i2c;
2975 obj->data.sysfs.fd =
2976 open_i2c_sensor(0, "temp", 2, &obj->data.sysfs.arg,
2977 obj->data.sysfs.devtype);
2979 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2980 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2982 char buf1[256], buf2[256], *fmt, *tz;
2985 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2994 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2995 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2997 END OBJ(iconv_start, 0)
2998 if (iconv_converting) {
2999 CRIT_ERR("You must stop your last iconv conversion before starting another");
3002 char iconv_from[CODEPAGE_LENGTH];
3003 char iconv_to[CODEPAGE_LENGTH];
3004 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3005 CRIT_ERR("Invalid arguments for iconv_start");
3008 new_iconv = iconv_open(iconv_to, iconv_from);
3009 if (new_iconv == (iconv_t)(-1)) {
3010 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3012 obj->a = register_iconv(&new_iconv);
3013 iconv_converting = 1;
3017 CRIT_ERR("Iconv requires arguments");
3019 END OBJ(iconv_stop, 0)
3020 iconv_converting = 0;
3023 END OBJ(totaldown, INFO_NET)
3025 obj->data.net = get_net_stat(arg);
3028 CRIT_ERR("totaldown needs argument");
3030 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
3032 obj->data.net = get_net_stat(arg);
3035 CRIT_ERR("totalup needs argument");
3038 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
3039 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
3040 END OBJ(upspeed, INFO_NET)
3042 obj->data.net = get_net_stat(arg);
3045 CRIT_ERR("upspeed needs argument");
3047 END OBJ(upspeedf, INFO_NET)
3049 obj->data.net = get_net_stat(arg);
3052 CRIT_ERR("upspeedf needs argument");
3055 END OBJ(upspeedgraph, INFO_NET)
3056 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
3058 sscanf(arg, "%63s %*i,%*i %*i", buf);
3059 obj->data.net = get_net_stat(buf);
3060 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
3061 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
3066 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3068 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3069 #endif /* !__OpenBSD__ */
3070 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3071 OBJ(apm_adapter, 0) END
3072 OBJ(apm_battery_life, 0) END
3073 OBJ(apm_battery_time, 0) END
3074 #endif /* __FreeBSD__ */
3078 obj->data.mail = parse_mail_args(IMAP, arg);
3079 obj->global_mode = 0;
3081 obj->global_mode = 1;
3084 OBJ(imap_messages, 0)
3087 obj->data.mail = parse_mail_args(IMAP, arg);
3088 obj->global_mode = 0;
3090 obj->global_mode = 1;
3096 obj->data.mail = parse_mail_args(POP3, arg);
3097 obj->global_mode = 0;
3099 obj->global_mode = 1;
3105 obj->data.mail = parse_mail_args(POP3, arg);
3106 obj->global_mode = 0;
3108 obj->global_mode = 1;
3112 OBJ(mpd_artist, INFO_MPD) END
3113 OBJ(mpd_title, INFO_MPD)
3116 sscanf (arg, "%d", &info.mpd.max_title_len);
3117 if (info.mpd.max_title_len > 0) {
3118 info.mpd.max_title_len++;
3120 CRIT_ERR ("mpd_title: invalid length argument");
3123 info.mpd.max_title_len = 0;
3126 END OBJ(mpd_random, INFO_MPD)
3127 END OBJ(mpd_repeat, INFO_MPD)
3128 END OBJ(mpd_elapsed, INFO_MPD)
3129 END OBJ(mpd_length, INFO_MPD)
3130 END OBJ(mpd_track, INFO_MPD)
3131 END OBJ(mpd_name, INFO_MPD)
3132 END OBJ(mpd_file, INFO_MPD)
3133 END OBJ(mpd_percent, INFO_MPD)
3134 END OBJ(mpd_album, INFO_MPD)
3135 END OBJ(mpd_vol, INFO_MPD)
3136 END OBJ(mpd_bitrate, INFO_MPD)
3137 END OBJ(mpd_status, INFO_MPD)
3138 END OBJ(mpd_bar, INFO_MPD)
3139 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3140 END OBJ(mpd_smart, INFO_MPD) END
3143 OBJ(xmms2_artist, INFO_XMMS2)
3144 END OBJ(xmms2_album, INFO_XMMS2)
3145 END OBJ(xmms2_title, INFO_XMMS2)
3146 END OBJ(xmms2_genre, INFO_XMMS2)
3147 END OBJ(xmms2_comment, INFO_XMMS2)
3148 END OBJ(xmms2_decoder, INFO_XMMS2)
3149 END OBJ(xmms2_transport, INFO_XMMS2)
3150 END OBJ(xmms2_url, INFO_XMMS2)
3151 END OBJ(xmms2_tracknr, INFO_XMMS2)
3152 END OBJ(xmms2_bitrate, INFO_XMMS2)
3153 END OBJ(xmms2_date, INFO_XMMS2)
3154 END OBJ(xmms2_id, INFO_XMMS2)
3155 END OBJ(xmms2_duration, INFO_XMMS2)
3156 END OBJ(xmms2_elapsed, INFO_XMMS2)
3157 END OBJ(xmms2_size, INFO_XMMS2)
3158 END OBJ(xmms2_status, INFO_XMMS2)
3159 END OBJ(xmms2_percent, INFO_XMMS2)
3160 END OBJ(xmms2_bar, INFO_XMMS2)
3161 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3162 END OBJ(xmms2_smart, INFO_XMMS2)
3166 OBJ(audacious_status, INFO_AUDACIOUS) END
3167 OBJ(audacious_title, INFO_AUDACIOUS)
3170 sscanf (arg, "%d", &info.audacious.max_title_len);
3171 if (info.audacious.max_title_len > 0) {
3172 info.audacious.max_title_len++;
3174 CRIT_ERR ("audacious_title: invalid length argument");
3179 OBJ(audacious_length, INFO_AUDACIOUS) END
3180 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3181 OBJ(audacious_position, INFO_AUDACIOUS) END
3182 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3183 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3184 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3185 OBJ(audacious_channels, INFO_AUDACIOUS) END
3186 OBJ(audacious_filename, INFO_AUDACIOUS) END
3187 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3188 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3189 OBJ(audacious_bar, INFO_AUDACIOUS)
3190 (void) scan_bar(arg, &obj->a, &obj->b);
3194 OBJ(bmpx_title, INFO_BMPX)
3195 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3197 OBJ(bmpx_artist, INFO_BMPX)
3198 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3200 OBJ(bmpx_album, INFO_BMPX)
3201 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3203 OBJ(bmpx_track, INFO_BMPX)
3204 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3206 OBJ(bmpx_uri, INFO_BMPX)
3207 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3209 OBJ(bmpx_bitrate, INFO_BMPX)
3210 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3216 int argc, delay, act_par;
3217 char *uri = (char *)malloc(128 * sizeof(char));
3218 char *action = (char *)malloc(64 * sizeof(char));
3220 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3221 obj->data.rss.uri = uri;
3222 obj->data.rss.delay = delay;
3223 obj->data.rss.action = action;
3224 obj->data.rss.act_par = act_par;
3228 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3234 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3235 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3236 ERR("hddtemp needs arguments");
3237 obj->type = OBJ_text;
3238 obj->data.s = strdup("${hddtemp}");
3243 #ifdef TCP_PORT_MONITOR
3244 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3245 int argc, port_begin, port_end, item, connection_index;
3247 memset(itembuf,0,sizeof(itembuf));
3249 /* massive argument checking */
3251 CRIT_ERR("tcp_portmon: needs arguments");
3253 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3254 if ( (argc != 3) && (argc != 4) )
3256 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3258 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3260 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3262 if ( port_begin > port_end )
3264 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3266 if ( strncmp(itembuf,"count",31) == 0 )
3268 else if ( strncmp(itembuf,"rip",31) == 0 )
3270 else if ( strncmp(itembuf,"rhost",31) == 0 )
3272 else if ( strncmp(itembuf,"rport",31) == 0 )
3274 else if ( strncmp(itembuf,"rservice",31) == 0 )
3276 else if ( strncmp(itembuf,"lip",31) == 0 )
3278 else if ( strncmp(itembuf,"lhost",31) == 0 )
3280 else if ( strncmp(itembuf,"lport",31) == 0 )
3282 else if ( strncmp(itembuf,"lservice",31) == 0 )
3286 CRIT_ERR("tcp_portmon: invalid item specified");
3288 if ( (argc==3) && (item!=COUNT) )
3290 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3292 if ( (argc==4) && (connection_index<0) )
3294 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3296 /* ok, args looks good. save the text object data */
3297 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3298 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3299 obj->data.tcp_port_monitor.item = item;
3300 obj->data.tcp_port_monitor.connection_index = connection_index;
3302 /* if the port monitor collection hasn't been created, we must create it */
3303 if ( !info.p_tcp_port_monitor_collection )
3305 info.p_tcp_port_monitor_collection =
3306 create_tcp_port_monitor_collection ();
3307 if ( !info.p_tcp_port_monitor_collection )
3309 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3313 /* if a port monitor for this port does not exist, create one and add it to the collection */
3314 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3316 tcp_port_monitor_t * p_monitor =
3317 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3320 CRIT_ERR("tcp_portmon: unable to create port monitor");
3322 /* add the newly created monitor to the collection */
3323 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3326 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3331 OBJ(entropy_avail, INFO_ENTROPY) END
3332 OBJ(entropy_poolsize, INFO_ENTROPY) END
3333 OBJ(entropy_bar, INFO_ENTROPY)
3334 (void) scan_bar(arg, &obj->a, &obj->b);
3339 ERR("unknown variable %s", s);
3340 obj->type = OBJ_text;
3341 snprintf(buf, 256, "${%s}", s);
3342 obj->data.s = strdup(buf);
3349 static struct text_object *create_plain_text(const char *s)
3351 struct text_object *obj;
3353 if (s == NULL || *s == '\0') {
3357 obj = new_text_object_internal();
3359 obj->type = OBJ_text;
3360 obj->data.s = strdup(s);
3364 static struct text_object_list *extract_variable_text_internal(const char *p)
3366 struct text_object_list *retval;
3367 struct text_object *obj;
3370 retval = malloc(sizeof(struct text_object_list));
3371 memset(retval, 0, sizeof(struct text_object_list));
3372 retval->text_object_count = 0;
3374 long line = text_lines;
3382 obj = create_plain_text(s);
3384 // allocate memory for the object
3385 retval->text_objects = realloc(retval->text_objects,
3386 sizeof(struct text_object) * (retval->text_object_count+1));
3387 // assign the new object to the end of the list.
3388 memcpy(&retval->text_objects[retval->text_object_count++],
3389 obj, sizeof(struct text_object));
3401 /* variable is either $foo or ${foo} */
3403 unsigned int brl = 1, brr = 0;
3406 while (*p && brl != brr) {
3407 if (*p == '{') brl++;
3408 if (*p == '}') brr++;
3416 while (*p && (isalnum((int) *p)
3421 /* copy variable to buffer */
3422 len = (p - s > 255) ? 255 : (p - s);
3423 strncpy(buf, s, len);
3432 /* if variable wasn't found from environment, use some special */
3438 if (strchr(buf, ' ')) {
3439 arg = strchr(buf, ' ');
3442 while (isspace((int) *arg))
3448 /* lowercase variable name */
3455 // create new object
3456 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3458 // allocate memory for the object
3459 retval->text_objects = realloc(retval->text_objects,
3460 sizeof(struct text_object) * (retval->text_object_count+1));
3461 // assign the new object to the end of the list.
3462 memcpy(&retval->text_objects[retval->text_object_count++],
3463 obj, sizeof(struct text_object));
3469 obj = create_plain_text("$");
3471 // allocate memory for the object
3472 retval->text_objects = realloc(retval->text_objects,
3473 sizeof(struct text_object) * (retval->text_object_count+1));
3474 // assign the new object to the end of the list.
3475 memcpy(&retval->text_objects[retval->text_object_count++],
3476 obj, sizeof(struct text_object));
3483 obj = create_plain_text(s);
3485 // allocate memory for the object
3486 retval->text_objects = realloc(retval->text_objects,
3487 sizeof(struct text_object) * (retval->text_object_count+1));
3488 // assign the new object to the end of the list.
3489 memcpy(&retval->text_objects[retval->text_object_count++],
3490 obj, sizeof(struct text_object));
3495 ERR("one or more $endif's are missing");
3501 static void extract_variable_text(const char *p)
3503 struct text_object_list *list;
3505 free_text_objects(text_object_count, text_objects);
3506 text_object_count = 0;
3507 text_objects = NULL;
3510 list = extract_variable_text_internal(p);
3511 text_objects = list->text_objects;
3512 text_object_count = list->text_object_count;
3519 void parse_conky_vars(char * text, char * p, struct information *cur) {
3520 struct text_object_list *object_list = extract_variable_text_internal(text);
3521 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3525 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3530 char buff_in[P_MAX_SIZE] = {0};
3531 iconv_converting = 0;
3534 for (i = 0; i < object_count; i++) {
3535 struct text_object *obj = &objs[i];
3537 #define OBJ(a) break; case OBJ_##a:
3539 switch (obj->type) {
3542 ERR("not implemented obj type %d",
3547 /* does anyone have decimals in acpi temperature? */
3549 snprintf(p, p_max_size, "%d", (int)
3550 get_acpi_temperature(obj->
3554 snprintf(p, 5, "%d ", (int)
3555 get_acpi_temperature(obj->
3560 /* does anyone have decimals in acpi temperature? */
3562 snprintf(p, p_max_size, "%d", (int)
3563 ((get_acpi_temperature(obj->
3565 i)+ 40) * 9.0 / 5 - 40));
3567 snprintf(p, 5, "%d ", (int)
3568 ((get_acpi_temperature(obj->
3570 i)+ 40) * 9.0 / 5 - 40));
3572 #endif /* !__OpenBSD__ */
3575 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3581 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3583 /* OpenBSD has no such flag (SUSv2) */
3584 obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->data.cpu_index);
3589 #if defined(__linux__)
3592 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3597 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3601 OBJ(wireless_essid) {
3602 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3604 OBJ(wireless_mode) {
3605 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3607 OBJ(wireless_bitrate) {
3608 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3611 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3613 OBJ(wireless_link_qual) {
3615 snprintf(p, p_max_size, "%d", obj->data.net->link_qual);
3617 snprintf(p, 4, "%d ", obj->data.net->link_qual);
3619 OBJ(wireless_link_qual_max) {
3621 snprintf(p, p_max_size, "%d", obj->data.net->link_qual_max);
3623 snprintf(p, 4, "%d ", obj->data.net->link_qual_max);
3625 OBJ(wireless_link_qual_perc) {
3626 if(obj->data.net->link_qual_max > 0) {
3628 snprintf(p, p_max_size, "%.0f%%", (double)obj->data.net->link_qual / obj->data.net->link_qual_max * 100);
3630 snprintf(p, 5, "%.0f%% ", (double)obj->data.net->link_qual / obj->data.net->link_qual_max * 100);
3631 } else snprintf(p, p_max_size, "unk");
3633 OBJ(wireless_link_bar) {
3634 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3636 #endif /* HAVE_IWLIB */
3638 #endif /* __linux__ */
3642 get_freq_dynamic(p, 6, "%.0f ", 1 );
3644 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3650 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3652 get_freq_dynamic(p, 6, "%.2f ", 1000);
3656 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3658 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
3664 get_adt746x_cpu(p, p_max_size);
3667 get_adt746x_fan(p, p_max_size);
3670 get_acpi_fan(p, p_max_size);
3672 OBJ(acpiacadapter) {
3673 get_acpi_ac_adapter(p, p_max_size);
3676 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3679 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3681 OBJ(battery_percent) {
3682 snprintf(p, p_max_size, "%d",
3683 get_battery_perct(obj->data.s));
3686 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3688 #endif /* __OpenBSD__ */
3690 human_readable(cur->buffers * 1024, p, 255);
3693 human_readable(cur->cached * 1024, p, 255);
3696 if (obj->data.cpu_index > info.cpu_count) {
3697 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3698 CRIT_ERR("attempting to use more CPUs then you have!");
3701 snprintf(p, p_max_size, "%*d", pad_percents,
3702 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3705 snprintf(p, 4, "%*d ",
3707 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3713 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3716 new_graph(p, obj->a,
3717 obj->b, obj->c, obj->d,
3718 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3722 new_fg(p, obj->data.l);
3754 #if defined(__linux__)
3756 snprintf(p, p_max_size, "%s", i8k.version);
3759 snprintf(p, p_max_size, "%s", i8k.bios);
3762 snprintf(p, p_max_size, "%s", i8k.serial);
3765 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3767 OBJ(i8k_cpu_tempf) {
3769 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3770 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3772 OBJ(i8k_left_fan_status) {
3773 int left_fan_status;
3774 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3775 if(left_fan_status == 0) {
3776 snprintf(p, p_max_size,"off");
3777 } if(left_fan_status == 1) {
3778 snprintf(p, p_max_size, "low");
3779 } if(left_fan_status == 2) {
3780 snprintf(p, p_max_size, "high");
3784 OBJ(i8k_right_fan_status) {
3785 int right_fan_status;
3786 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3787 if(right_fan_status == 0) {
3788 snprintf(p, p_max_size,"off");
3789 } if(right_fan_status == 1) {
3790 snprintf(p, p_max_size, "low");
3791 } if(right_fan_status == 2) {
3792 snprintf(p, p_max_size, "high");
3795 OBJ(i8k_left_fan_rpm) {
3796 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3798 OBJ(i8k_right_fan_rpm) {
3799 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3801 OBJ(i8k_ac_status) {
3803 sscanf(i8k.ac_status, "%d", &ac_status);
3804 if(ac_status == -1) {
3805 snprintf(p, p_max_size,"disabled (read i8k docs)");
3806 } if(ac_status == 0) {
3807 snprintf(p, p_max_size, "off");
3808 } if(ac_status == 1) {
3809 snprintf(p, p_max_size, "on");
3812 OBJ(i8k_buttons_status) {
3813 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3817 get_ibm_acpi_fan(p, p_max_size);
3820 get_ibm_acpi_temps();
3821 snprintf(p, p_max_size, "%d",
3822 ibm_acpi.temps[obj->data.sensor]);
3825 get_ibm_acpi_volume(p, p_max_size);
3827 OBJ(ibm_brightness) {
3828 get_ibm_acpi_brightness(p, p_max_size);
3831 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3833 #endif /* __linux__ */
3836 OBJ(obsd_sensors_temp) {
3837 obsd_sensors.device = sensor_device;
3838 update_obsd_sensors();
3839 snprintf(p, p_max_size, "%.1f",
3840 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3843 OBJ(obsd_sensors_fan) {
3844 obsd_sensors.device = sensor_device;
3845 update_obsd_sensors();
3846 snprintf(p, p_max_size, "%d",
3847 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3850 OBJ(obsd_sensors_volt) {
3851 obsd_sensors.device = sensor_device;
3852 update_obsd_sensors();
3853 snprintf(p, p_max_size, "%.2f",
3854 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3858 get_obsd_vendor(p, p_max_size);
3862 get_obsd_product(p, p_max_size);
3864 #endif /* __OpenBSD__ */
3867 new_font(p, obj->data.s);
3869 void format_diskio(unsigned int diskio_value)
3872 if (diskio_value > 1024*1024) {
3873 snprintf(p, p_max_size, "%.1fGiB",
3874 (double)diskio_value/1024/1024);
3875 } else if (diskio_value > 1024) {
3876 snprintf(p, p_max_size, "%.1fMiB",
3877 (double)diskio_value/1024);
3878 } else if (diskio_value > 0) {
3879 snprintf(p, p_max_size, "%dKiB", diskio_value);
3881 snprintf(p, p_max_size, "%dB", diskio_value);
3884 if (diskio_value > 1024*1024) {
3885 snprintf(p, 12, "%.1fGiB ",
3886 (double)diskio_value/1024/1024);
3887 } else if (diskio_value > 1024) {
3888 snprintf(p, 12, "%.1fMiB ",
3889 (double)diskio_value/1024);
3890 } else if (diskio_value > 0) {
3891 snprintf(p, 12, "%dKiB ", diskio_value);
3893 snprintf(p, 12, "%dB ", diskio_value);
3898 format_diskio(diskio_value);
3901 format_diskio(diskio_write_value);
3904 format_diskio(diskio_read_value);
3907 new_graph(p, obj->a,
3908 obj->b, obj->c, obj->d,
3909 diskio_value, obj->e, 1);
3911 OBJ(diskiograph_read) {
3912 new_graph(p, obj->a,
3913 obj->b, obj->c, obj->d,
3914 diskio_read_value, obj->e, 1);
3916 OBJ(diskiograph_write) {
3917 new_graph(p, obj->a,
3918 obj->b, obj->c, obj->d,
3919 diskio_write_value, obj->e, 1);
3923 snprintf(p, p_max_size, "%d",
3924 (int) (obj->data.net->
3928 snprintf(p, 6, "%d ",
3929 (int) (obj->data.net->
3935 snprintf(p, p_max_size, "%.1f",
3937 recv_speed / 1024.0);
3939 snprintf(p, 8, "%.1f ",
3941 recv_speed / 1024.0);
3943 OBJ(downspeedgraph) {
3945 if (obj->data.net->recv_speed == 0)
3946 obj->data.net->recv_speed = 0.01;
3948 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3949 (obj->data.net->recv_speed /
3950 1024.0), obj->e, 1);
3954 i = obj->data.ifblock.pos - 1;
3964 snprintf(p, p_max_size, "%u.%u.%u.%u",
3965 obj->data.net->addr.
3967 obj->data.net->addr.
3969 obj->data.net->addr.
3971 obj->data.net->addr.
3975 #if defined(IMLIB2) && defined(X11)
3980 Imlib_Image image, buffer;
3981 image = imlib_load_image(obj->data.s);
3982 imlib_context_set_image(image);
3985 w = imlib_image_get_width();
3986 h = imlib_image_get_height();
3987 buffer = imlib_create_image(w, h);
3988 imlib_context_set_display(display);
3989 imlib_context_set_drawable(window.drawable);
3990 imlib_context_set_colormap(DefaultColormap(display, screen));
3991 imlib_context_set_visual(DefaultVisual(display, screen));
3992 imlib_context_set_image(buffer);
3993 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3994 imlib_render_image_on_drawable(text_start_x, text_start_y);
3996 imlib_context_set_image(image);
4003 FILE *fp = popen(obj->data.s, "r");
4004 int length = fread(p, 1, p_max_size, fp);
4007 /*output[length] = '\0';
4008 if (length > 0 && output[length - 1] == '\n') {
4009 output[length - 1] = '\0';
4012 if (length > 0 && p[length - 1] == '\n') {
4013 p[length - 1] = '\0';
4016 //parse_conky_vars(output, p, cur);
4020 FILE *fp = popen(obj->data.s, "r");
4021 int n2 = fread(p, 1, p_max_size, fp);
4025 if (n2 && p[n2 - 1] == '\n')
4034 if (sscanf(p, "%lf", &barnum) == 0) {
4035 ERR("reading execbar value failed (perhaps it's not the correct format?)");
4037 if (barnum > 100 || barnum < 0) {
4038 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
4040 barnum = barnum / 100.0;
4041 new_bar(p, 0, 4, (int) (barnum * 255.0));
4047 FILE *fp = popen(obj->data.s, "r");
4048 int n2 = fread(p, 1, p_max_size, fp);
4052 if (n2 && p[n2 - 1] == '\n')
4061 if (sscanf(p, "%lf", &barnum) == 0) {
4062 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
4064 if (barnum > 100 || barnum < 0) {
4065 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
4067 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
4072 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4073 new_bar(p, 0, 4, (int) obj->f);
4076 FILE *fp = popen(obj->data.execi.cmd, "r");
4077 int n2 = fread(p, 1, p_max_size, fp);
4080 if (n2 && p[n2 - 1] == '\n')
4089 if (sscanf(p, "%f", &barnum) == 0) {
4090 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4092 if (barnum > 100 || barnum < 0) {
4093 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4095 obj->f = 255 * barnum / 100.0;
4096 new_bar(p, 0, 4, (int) obj->f);
4098 obj->data.execi.last_update =
4099 current_update_time;
4103 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4104 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4107 FILE *fp = popen(obj->data.execi.cmd, "r");
4108 int n2 = fread(p, 1, p_max_size, fp);
4111 if (n2 && p[n2 - 1] == '\n')
4120 if (sscanf(p, "%f", &barnum) == 0) {
4121 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4123 if (barnum > 100 || barnum < 0) {
4124 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4127 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4129 obj->data.execi.last_update = current_update_time;
4135 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4136 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4138 char *output = obj->data.execi.buffer;
4139 FILE *fp = popen(obj->data.execi.cmd, "r");
4140 //int length = fread(output, 1, text_buffer_size, fp);
4141 int length = fread(output, 1, text_buffer_size, fp);
4144 output[length] = '\0';
4145 if (length > 0 && output[length - 1] == '\n') {
4146 output[length - 1] = '\0';
4148 obj->data.execi.last_update = current_update_time;
4149 snprintf(p, p_max_size, "%s", output);
4151 //parse_conky_vars(output, p, cur);
4154 if (!obj->data.texeci.p_timed_thread)
4156 obj->data.texeci.p_timed_thread=
4157 timed_thread_create ((void*)threaded_exec, (void*) obj, obj->data.texeci.interval * 1000000);
4158 if (!obj->data.texeci.p_timed_thread)
4159 ERR("Error creating texeci timed thread");
4160 timed_thread_register (obj->data.texeci.p_timed_thread, &obj->data.texeci.p_timed_thread);
4161 if (timed_thread_run (obj->data.texeci.p_timed_thread))
4162 ERR("Error running texeci timed thread");
4164 timed_thread_lock (obj->data.texeci.p_timed_thread);
4165 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4166 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4168 #endif /* HAVE_POPEN */
4170 if (obj->global_mode && info.mail) { // this means we use info
4171 if (!info.mail->p_timed_thread)
4173 info.mail->p_timed_thread =
4174 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4175 if (!info.mail->p_timed_thread)
4176 ERR("Error creating imap timed thread");
4177 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4178 if (timed_thread_run (info.mail->p_timed_thread))
4179 ERR("Error running imap timed thread");
4181 timed_thread_lock (info.mail->p_timed_thread);
4182 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4183 timed_thread_unlock (info.mail->p_timed_thread);
4184 } else if (obj->data.mail) { // this means we use obj
4185 if (!obj->data.mail->p_timed_thread)
4187 obj->data.mail->p_timed_thread =
4188 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4189 obj->data.mail->interval * 1000000);
4190 if (!obj->data.mail->p_timed_thread)
4191 ERR("Error creating imap timed thread");
4192 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4193 if (timed_thread_run (obj->data.mail->p_timed_thread))
4194 ERR("Error running imap timed thread");
4196 timed_thread_lock (obj->data.mail->p_timed_thread);
4197 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4198 timed_thread_unlock (obj->data.mail->p_timed_thread);
4199 } else if (!obj->a) { // something is wrong, warn once then stop
4200 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4204 OBJ(imap_messages) {
4205 if (obj->global_mode && info.mail) { // this means we use info
4206 if (!info.mail->p_timed_thread)
4208 info.mail->p_timed_thread =
4209 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4210 if (!info.mail->p_timed_thread)
4211 ERR("Error creating imap timed thread");
4212 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4213 if (timed_thread_run (info.mail->p_timed_thread))
4214 ERR("Error running imap timed thread");
4216 timed_thread_lock (info.mail->p_timed_thread);
4217 snprintf(p, p_max_size, "%lu", info.mail->messages);
4218 timed_thread_unlock (info.mail->p_timed_thread);
4219 } else if (obj->data.mail) { // this means we use obj
4220 if (!obj->data.mail->p_timed_thread)
4222 obj->data.mail->p_timed_thread =
4223 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4224 obj->data.mail->interval * 1000000);
4225 if (!obj->data.mail->p_timed_thread)
4226 ERR("Error creating imap timed thread");
4227 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4228 if (timed_thread_run (obj->data.mail->p_timed_thread))
4229 ERR("Error runninging imap timed thread");
4231 timed_thread_lock (obj->data.mail->p_timed_thread);
4232 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4233 timed_thread_lock (obj->data.mail->p_timed_thread);
4234 } else if (!obj->a) { // something is wrong, warn once then stop
4235 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4240 if (obj->global_mode && info.mail) { // this means we use info
4241 if (!info.mail->p_timed_thread)
4243 info.mail->p_timed_thread =
4244 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4245 if (!info.mail->p_timed_thread)
4246 ERR("Error creating pop3 timed thread");
4247 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4248 if (timed_thread_run (info.mail->p_timed_thread))
4249 ERR("Error running pop3 timed thread");
4251 timed_thread_lock (info.mail->p_timed_thread);
4252 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4253 timed_thread_unlock (info.mail->p_timed_thread);
4254 } else if (obj->data.mail) { // this means we use obj
4255 if (!obj->data.mail->p_timed_thread)
4257 obj->data.mail->p_timed_thread =
4258 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4259 obj->data.mail->interval * 1000000);
4260 if (!obj->data.mail->p_timed_thread)
4261 ERR("Error creating pop3 timed thread");
4262 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4263 if (timed_thread_run (obj->data.mail->p_timed_thread))
4264 ERR("Error running pop3 timed thread");
4266 timed_thread_lock (obj->data.mail->p_timed_thread);
4267 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4268 timed_thread_unlock (obj->data.mail->p_timed_thread);
4269 } else if (!obj->a) { // something is wrong, warn once then stop
4270 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4275 if (obj->global_mode && info.mail) { // this means we use info
4276 if (!info.mail->p_timed_thread)
4278 info.mail->p_timed_thread =
4279 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4280 if (!info.mail->p_timed_thread)
4281 ERR("Error creating pop3 timed thread");
4282 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4283 if (timed_thread_run (info.mail->p_timed_thread))
4284 ERR("Error running pop3 timed thread");
4286 timed_thread_lock (info.mail->p_timed_thread);
4287 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4288 timed_thread_unlock (info.mail->p_timed_thread);
4289 } else if (obj->data.mail) { // this means we use obj
4290 if (!obj->data.mail->p_timed_thread)
4292 obj->data.mail->p_timed_thread =
4293 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4294 obj->data.mail->interval * 1000000);
4295 if (!obj->data.mail->p_timed_thread)
4296 ERR("Error creating pop3 timed thread");
4297 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4298 if (timed_thread_run (obj->data.mail->p_timed_thread))
4299 ERR("Error running pop3 timed thread");
4301 timed_thread_lock (obj->data.mail->p_timed_thread);
4302 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4303 timed_thread_unlock (obj->data.mail->p_timed_thread);
4304 } else if (!obj->a) { // something is wrong, warn once then stop
4305 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4310 if (obj->data.fs != NULL) {
4311 if (obj->data.fs->size == 0)
4330 if (obj->data.fs != NULL)
4331 human_readable(obj->data.fs->avail,
4335 if (obj->data.fs != NULL) {
4336 if (obj->data.fs->size)
4337 snprintf(p, p_max_size, "%*d",
4346 snprintf(p, p_max_size, "0");
4350 if (obj->data.fs != NULL)
4351 human_readable(obj->data.fs->size,
4355 if (obj->data.fs != NULL)
4356 human_readable(obj->data.fs->size -
4357 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4361 if (obj->data.fs != NULL) {
4362 if (obj->data.fs->size == 0)
4380 if (obj->data.fs != NULL) {
4381 if (obj->data.fs->size)
4382 snprintf(p, 4, "%d",
4392 snprintf(p, p_max_size, "0");
4396 float *v = info.loadavg;
4398 if (obj->data.loadavg[2])
4399 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4400 v[obj->data.loadavg[0] -
4402 v[obj->data.loadavg[1] -
4404 v[obj->data.loadavg[2] -
4406 else if (obj->data.loadavg[1])
4407 snprintf(p, p_max_size, "%.2f %.2f",
4408 v[obj->data.loadavg[0] -
4410 v[obj->data.loadavg[1] -
4412 else if (obj->data.loadavg[0])
4413 snprintf(p, p_max_size, "%.2f",
4414 v[obj->data.loadavg[0] -
4418 new_goto(p, obj->data.i);
4421 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4424 new_hr(p, obj->data.i);
4428 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4431 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4433 if(!strcmp(obj->data.rss.action, "feed_title")) {
4435 if(str[strlen(str)-1] == '\n')
4436 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4437 snprintf(p, p_max_size, "%s", str);
4438 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4439 if(obj->data.rss.act_par < data->item_count) {
4440 str = data->items[obj->data.rss.act_par].title;
4441 if(str[strlen(str)-1] == '\n')
4442 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4443 snprintf(p, p_max_size, "%s", str);
4445 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4446 if(obj->data.rss.act_par < data->item_count) {
4447 str = data->items[obj->data.rss.act_par].description;
4448 if(str[strlen(str)-1] == '\n')
4449 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4450 snprintf(p, p_max_size, "%s", str);
4452 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4453 if(data->item_count > 0) {
4457 if(obj->data.rss.act_par > data->item_count)
4458 show = data->item_count;
4459 else show = obj->data.rss.act_par;
4460 for(itmp = 0; itmp < show; itmp++) {
4461 PRSS_Item *item = &data->items[itmp];
4464 if(itmp>0) // don't add new line before first item
4465 strncat(p, "\n", p_max_size);
4466 if(str[strlen(str)-1] == '\n')
4467 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4468 strncat(p, str, p_max_size);
4481 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4482 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4484 snprintf(p, p_max_size, "N/A");
4485 } else if (unit == '*') {
4486 snprintf(p, p_max_size, "%s", temp);
4488 snprintf(p, p_max_size, "%s°%c", temp, unit);
4493 new_offset(p, obj->data.i);
4496 new_voffset(p, obj->data.i);
4502 r = get_sysfs_info(&obj->data.sysfs.fd,
4503 obj->data.sysfs.arg,
4504 obj->data.sysfs.devtype,
4505 obj->data.sysfs.type);
4507 if (r >= 100.0 || r == 0)
4508 snprintf(p, p_max_size, "%d", (int) r);
4510 snprintf(p, p_max_size, "%.1f", r);
4515 r = get_sysfs_info(&obj->data.sysfs.fd,
4516 obj->data.sysfs.arg,
4517 obj->data.sysfs.devtype,
4518 obj->data.sysfs.type);
4520 if (r >= 100.0 || r == 0)
4521 snprintf(p, p_max_size, "%d", (int) r);
4523 snprintf(p, p_max_size, "%.1f", r);
4528 r = get_sysfs_info(&obj->data.sysfs.fd,
4529 obj->data.sysfs.arg,
4530 obj->data.sysfs.devtype,
4531 obj->data.sysfs.type);
4533 if (r >= 100.0 || r == 0)
4534 snprintf(p, p_max_size, "%d", (int) r);
4536 snprintf(p, p_max_size, "%.1f", r);
4538 #endif /* !__OpenBSD__ */
4540 new_alignr(p, obj->data.i);
4543 new_alignc(p, obj->data.i);
4546 struct information *my_info =
4547 malloc(sizeof(struct information));
4548 memcpy(my_info, cur, sizeof(struct information));
4549 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4550 if (strlen(p) != 0) {
4551 i = obj->data.ifblock.pos;
4561 if ((obj->data.ifblock.s)
4562 && (stat(obj->data.ifblock.s, &tmp) ==
4564 i = obj->data.ifblock.pos;
4567 if (obj->data.ifblock.str) {
4568 if (!check_contains(obj->data.ifblock.s,
4569 obj->data.ifblock.str)) {
4570 i = obj->data.ifblock.pos;
4579 if ((obj->data.ifblock.s)
4580 && (!check_mount(obj->data.ifblock.s))) {
4581 i = obj->data.ifblock.pos;
4588 if ((obj->data.ifblock.s)
4589 && system(obj->data.ifblock.s)) {
4590 i = obj->data.ifblock.pos;
4597 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4600 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4605 human_readable(cur->mem * 1024, p, 255);
4608 human_readable(cur->memmax * 1024, p, 255);
4613 snprintf(p, p_max_size, "%*Lu",
4618 snprintf(p, 4, "%*Lu ",
4625 new_bar(p, obj->data.pair.a,
4627 cur->memmax ? (cur->mem * 255) /
4632 new_graph(p, obj->a,
4633 obj->b, obj->c, obj->d,
4634 cur->memmax ? (cur->mem * 100.0) /
4635 (cur->memmax) : 0.0, 100, 1);
4639 snprintf(p, p_max_size, "%d",
4640 mixer_get_avg(obj->data.l));
4643 snprintf(p, p_max_size, "%d",
4644 mixer_get_left(obj->data.l));
4647 snprintf(p, p_max_size, "%d",
4648 mixer_get_right(obj->data.l));
4651 new_bar(p, obj->data.mixerbar.w,
4652 obj->data.mixerbar.h,
4653 mixer_get_avg(obj->data.mixerbar.
4657 new_bar(p, obj->data.mixerbar.w,
4658 obj->data.mixerbar.h,
4659 mixer_get_left(obj->data.mixerbar.
4663 new_bar(p, obj->data.mixerbar.w,
4664 obj->data.mixerbar.h,
4665 mixer_get_right(obj->data.mixerbar.
4671 snprintf(p, p_max_size, "%d", cur->mail_count);
4674 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4675 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4678 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4682 snprintf(p, p_max_size, "%s",
4683 cur->uname_s.nodename);
4686 new_outline(p, obj->data.l);
4690 snprintf(p, p_max_size, "%hu", cur->procs);
4692 snprintf(p, 5, "%hu ",
4695 OBJ(running_processes) {
4697 snprintf(p, p_max_size, "%hu",
4700 snprintf(p, 3, "%hu ",
4704 snprintf(p, p_max_size, "%s", obj->data.s);
4707 new_bg(p, obj->data.l);
4710 new_stippled_hr(p, obj->data.pair.a,
4714 human_readable(cur->swap * 1024, p, 255);
4717 human_readable(cur->swapmax * 1024, p,
4721 if (cur->swapmax == 0) {
4722 strncpy(p, "No swap", 255);
4725 snprintf(p, 255, "%*Lu",
4731 snprintf(p, 4, "%*Lu ",
4739 new_bar(p, obj->data.pair.a,
4741 cur->swapmax ? (cur->swap * 255) /
4742 (cur->swapmax) : 0);
4745 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4748 time_t t = time(NULL);
4749 struct tm *tm = localtime(&t);
4750 setlocale(LC_TIME, "");
4751 strftime(p, p_max_size, obj->data.s, tm);
4754 time_t t = time(NULL);
4755 struct tm *tm = gmtime(&t);
4756 strftime(p, p_max_size, obj->data.s, tm);
4760 if (obj->data.tztime.tz) {
4761 oldTZ = getenv("TZ");
4762 setenv("TZ", obj->data.tztime.tz, 1);
4765 time_t t = time(NULL);
4766 struct tm *tm = localtime(&t);
4767 setlocale(LC_TIME, "");
4768 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4770 setenv("TZ", oldTZ, 1);
4775 // Needless to free oldTZ since getenv gives ptr to static data
4778 human_readable(obj->data.net->recv, p,
4782 human_readable(obj->data.net->trans, p,
4786 snprintf(p, p_max_size, "%d", total_updates);
4790 snprintf(p, p_max_size, "%d",
4791 (int) (obj->data.net->
4795 snprintf(p, 6, "%d ",
4796 (int) (obj->data.net->
4802 snprintf(p, p_max_size, "%.1f",
4804 trans_speed / 1024.0);
4806 snprintf(p, 8, "%.1f ",
4808 trans_speed / 1024.0);
4812 if (obj->data.net->trans_speed == 0)
4813 obj->data.net->trans_speed = 0.01;
4815 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4816 (obj->data.net->trans_speed /
4817 1024.0), obj->e, 1);
4820 format_seconds_short(p, p_max_size,
4824 format_seconds(p, p_max_size, (int) cur->uptime);
4827 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4830 msg = get_apm_adapter();
4831 snprintf(p, p_max_size, "%s", msg);
4834 OBJ(apm_battery_life) {
4836 msg = get_apm_battery_life();
4837 snprintf(p, p_max_size, "%s", msg);
4840 OBJ(apm_battery_time) {
4842 msg = get_apm_battery_time();
4843 snprintf(p, p_max_size, "%s", msg);
4846 #endif /* __FreeBSD__ __OpenBSD__ */
4850 snprintf(p, cur->mpd.max_title_len > 0 ?
4851 cur->mpd.max_title_len : p_max_size, "%s",
4855 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4858 snprintf(p, p_max_size, "%s", cur->mpd.album);
4861 snprintf(p, p_max_size, "%s", cur->mpd.random);
4864 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4867 snprintf(p, p_max_size, "%s", cur->mpd.track);
4870 snprintf(p, p_max_size, "%s", cur->mpd.name);
4873 snprintf(p, p_max_size, "%s", cur->mpd.file);
4876 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4879 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4882 snprintf(p, p_max_size, "%s", cur->mpd.status);
4885 int days = 0, hours = 0, minutes =
4887 int tmp = cur->mpd.elapsed;
4888 while (tmp >= 86400) {
4892 while (tmp >= 3600) {
4902 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4903 days, hours, minutes,
4906 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4909 snprintf(p, p_max_size, "%i:%02i", minutes,
4913 int days = 0, hours = 0, minutes =
4915 int tmp = cur->mpd.length;
4916 while (tmp >= 86400) {
4920 while (tmp >= 3600) {
4930 snprintf(p, p_max_size,
4931 "%i days %i:%02i:%02i",
4932 days, hours, minutes,
4935 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4938 snprintf(p, p_max_size, "%i:%02i", minutes,
4942 snprintf(p, p_max_size, "%2.0f",
4943 cur->mpd.progress * 100);
4946 new_bar(p, obj->data.pair.a,
4948 (int) (cur->mpd.progress *
4952 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.artist) < 2) {
4953 snprintf(p, p_max_size, "%s", cur->mpd.file);
4955 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4961 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4964 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4967 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4970 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4972 OBJ(xmms2_comment) {
4973 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4975 OBJ(xmms2_decoder) {
4976 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4978 OBJ(xmms2_transport) {
4979 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4982 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4985 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4988 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4990 OBJ(xmms2_tracknr) {
4991 if (cur->xmms2.tracknr != -1)
4992 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4994 OBJ(xmms2_bitrate) {
4995 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4998 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5001 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5003 OBJ(xmms2_elapsed) {
5004 int tmp = cur->xmms2.elapsed;
5005 snprintf(p, p_max_size, "%02d:%02d",
5006 tmp / 60000, (tmp / 1000) % 60);
5008 OBJ(xmms2_duration) {
5009 int tmp = cur->xmms2.duration;
5010 snprintf(p, p_max_size, "%02d:%02d",
5011 tmp / 60000, (tmp / 1000) % 60);
5013 OBJ(xmms2_percent) {
5014 snprintf(p, p_max_size, "%2.0f",
5015 cur->xmms2.progress * 100);
5018 new_bar(p, obj->data.pair.a,
5020 (int) (cur->xmms2.progress *
5024 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
5025 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5027 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
5032 OBJ(audacious_status) {
5033 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
5035 OBJ(audacious_title) {
5036 snprintf(p, cur->audacious.max_title_len > 0 ?
5037 cur->audacious.max_title_len : p_max_size, "%s",
5038 cur->audacious.items[AUDACIOUS_TITLE]);
5040 OBJ(audacious_length) {
5041 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
5043 OBJ(audacious_length_seconds) {
5044 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5046 OBJ(audacious_position) {
5047 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
5049 OBJ(audacious_position_seconds) {
5050 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5052 OBJ(audacious_bitrate) {
5053 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
5055 OBJ(audacious_frequency) {
5056 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
5058 OBJ(audacious_channels) {
5059 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
5061 OBJ(audacious_filename) {
5062 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
5064 OBJ(audacious_playlist_length) {
5065 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5067 OBJ(audacious_playlist_position) {
5068 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5070 OBJ(audacious_bar) {
5072 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5073 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5074 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
5079 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5082 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5085 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5088 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5091 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5094 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5098 if (obj->data.top.type == TOP_NAME
5099 && obj->data.top.num >= 0
5100 && obj->data.top.num < 10) {
5101 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
5102 } else if (obj->data.top.type == TOP_CPU
5103 && obj->data.top.num >= 0
5104 && obj->data.top.num < 10) {
5105 snprintf(p, 7, "%7.3f",
5106 cur->cpu[obj->data.top.
5108 } else if (obj->data.top.type == TOP_PID
5109 && obj->data.top.num >= 0
5110 && obj->data.top.num < 10) {
5111 snprintf(p, 8, "%7i",
5112 cur->cpu[obj->data.top.
5114 } else if (obj->data.top.type == TOP_MEM
5115 && obj->data.top.num >= 0
5116 && obj->data.top.num < 10) {
5117 snprintf(p, 7, "%7.3f",
5118 cur->cpu[obj->data.top.
5123 if (obj->data.top.type == TOP_NAME
5124 && obj->data.top.num >= 0
5125 && obj->data.top.num < 10) {
5126 snprintf(p, 17, "%-17s",
5127 cur->memu[obj->data.top.
5129 } else if (obj->data.top.type == TOP_CPU
5130 && obj->data.top.num >= 0
5131 && obj->data.top.num < 10) {
5132 snprintf(p, 7, "%7.3f",
5133 cur->memu[obj->data.top.
5135 } else if (obj->data.top.type == TOP_PID
5136 && obj->data.top.num >= 0
5137 && obj->data.top.num < 10) {
5138 snprintf(p, 8, "%7i",
5139 cur->memu[obj->data.top.
5141 } else if (obj->data.top.type == TOP_MEM
5142 && obj->data.top.num >= 0
5143 && obj->data.top.num < 10) {
5144 snprintf(p, 7, "%7.3f",
5145 cur->memu[obj->data.top.
5152 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5153 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5155 obj->data.tail.last_update = current_update_time;
5159 fp = fopen(obj->data.tail.logfile, "rt");
5161 /* Send one message, but do not consistently spam on
5162 * missing logfiles. */
5163 if(obj->data.tail.readlines != 0) {
5164 ERR("tail logfile failed to open");
5165 strcpy(obj->data.tail.buffer, "Logfile Missing");
5167 obj->data.tail.readlines = 0;
5168 snprintf(p, p_max_size, "Logfile Missing");
5171 obj->data.tail.readlines = 0;
5172 /* -1 instead of 0 to avoid counting a trailing newline */
5173 fseek(fp, -1, SEEK_END);
5174 bsize = ftell(fp) + 1;
5175 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5176 nl = rev_fcharfind(fp, '\n', iter);
5180 obj->data.tail.readlines = iter;
5181 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5182 fseek(fp, 0, SEEK_SET);
5185 fseek(fp, nl+1, SEEK_SET);
5188 /* Make sure bsize is at least 1 byte smaller than
5189 * the buffer max size. */
5190 if(bsize > (long)((text_buffer_size*20) - 1)) {
5191 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5192 bsize = text_buffer_size*20 - 1;
5194 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5197 /* Clean up trailing newline, make sure the buffer
5198 * is null terminated. */
5199 if(obj->data.tail.buffer[bsize-1] == '\n')
5200 obj->data.tail.buffer[bsize-1] = '\0';
5202 obj->data.tail.buffer[bsize] = '\0';
5203 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5206 strcpy(obj->data.tail.buffer, "Logfile Empty");
5207 snprintf(p, p_max_size, "Logfile Empty");
5210 } /* if cur_upd_time >= */
5212 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5216 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5217 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5219 obj->data.tail.last_update = current_update_time;
5223 fp = fopen(obj->data.tail.logfile, "rt");
5225 /* Send one message, but do not consistently spam on
5226 * missing logfiles. */
5227 if(obj->data.tail.readlines != 0) {
5228 ERR("head logfile failed to open");
5229 strcpy(obj->data.tail.buffer, "Logfile Missing");
5231 obj->data.tail.readlines = 0;
5232 snprintf(p, p_max_size, "Logfile Missing");
5234 obj->data.tail.readlines = 0;
5235 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5236 nl = fwd_fcharfind(fp, '\n', iter);
5240 obj->data.tail.readlines = iter;
5241 /* Make sure nl is at least 1 byte smaller than
5242 * the buffer max size. */
5243 if(nl > (long)((text_buffer_size*20) - 1)) {
5244 nl = text_buffer_size*20 - 1;
5246 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5249 /* Clean up trailing newline, make sure the buffer
5250 * is null terminated. */
5251 if (obj->data.tail.buffer[nl-1] == '\n') {
5252 obj->data.tail.buffer[nl-1] = '\0';
5255 obj->data.tail.buffer[nl] = '\0';
5257 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5260 strcpy(obj->data.tail.buffer, "Logfile Empty");
5261 snprintf(p, p_max_size, "Logfile Empty");
5263 } /* if fp == null */
5264 } /* cur_upd_time >= */
5266 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5269 #ifdef TCP_PORT_MONITOR
5272 /* grab a pointer to this port monitor */
5273 tcp_port_monitor_t * p_monitor =
5274 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5275 obj->data.tcp_port_monitor.port_range_begin,
5276 obj->data.tcp_port_monitor.port_range_end );
5278 snprintf(p, p_max_size, "monitor not found");
5282 /* now grab the text of interest */
5283 if ( peek_tcp_port_monitor( p_monitor,
5284 obj->data.tcp_port_monitor.item,
5285 obj->data.tcp_port_monitor.connection_index,
5286 p, p_max_size ) != 0 )
5288 snprintf(p, p_max_size, "monitor peek error");
5297 iconv_converting = 1;
5298 iconv_selected = obj->a;
5303 iconv_converting = 0;
5309 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5311 OBJ(entropy_poolsize)
5313 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5317 double entropy_perc;
5318 entropy_perc = (double)cur->entropy.entropy_avail /
5319 (double)cur->entropy.poolsize;
5320 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5328 unsigned int a = strlen(p);
5331 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5333 size_t dummy1, dummy2;
5334 char *ptr = buff_in;
5337 dummy1 = dummy2 = a;
5339 strncpy(buff_in, p, P_MAX_SIZE);
5341 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5342 while (dummy1 > 0) {
5343 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5345 ERR("Iconv codeset conversion failed");
5350 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5361 double current_update_time, last_update_time;
5363 static void generate_text()
5365 struct information *cur = &info;
5373 current_update_time = get_time();
5376 /* fix diskio rates to b/s (use update_interval */
5377 diskio_read_value = diskio_read_value / update_interval;
5378 diskio_write_value = diskio_write_value / update_interval;
5379 diskio_value = diskio_value / update_interval;
5382 /* add things to the buffer */
5388 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5390 if (stuff_in_upper_case) {
5401 last_update_time = current_update_time;
5408 static void set_font()
5412 if (window.xftdraw != NULL) {
5413 XftDrawDestroy(window.xftdraw);
5415 window.xftdraw = XftDrawCreate(display, window.drawable,
5416 DefaultVisual(display,
5418 DefaultColormap(display,
5423 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5429 static inline int get_string_width(const char *s)
5432 return *s ? calc_text_width(s, strlen(s)) : 0;
5438 static inline int get_string_width_special(char *s)
5451 if (*p == SPECIAL_CHAR) {
5452 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5453 for (i = 0; i < strlen(p); i++) {
5454 *(p + i) = *(p + i + 1);
5456 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5457 width += specials[special_index+index].width;
5464 if (strlen(final) > 1) {
5465 width += calc_text_width(final, strlen(final));
5475 static void text_size_updater(char *s);
5477 int last_font_height;
5478 static void update_text_area()
5482 /* update text size if it isn't fixed */
5487 text_width = minimum_width;
5490 last_font_height = font_height();
5491 for_each_line(text_buffer, text_size_updater);
5493 if (text_height < minimum_height)
5494 text_height = minimum_height;
5495 if (text_width > maximum_width && maximum_width > 0)
5496 text_width = maximum_width;
5499 /* get text position on workarea */
5500 switch (text_alignment) {
5507 x = workarea[2] - text_width - gap_x;
5514 y = workarea[3] - text_height - gap_y;
5518 x = workarea[2] - text_width - gap_x;
5519 y = workarea[3] - text_height - gap_y;
5523 case NONE: // Let the WM manage the window
5534 if (own_window && !fixed_pos) {
5537 text_start_x = border_margin + 1;
5538 text_start_y = border_margin + 1;
5539 window.x = x - border_margin - 1;
5540 window.y = y - border_margin - 1;
5544 /* If window size doesn't match to workarea's size, then window
5545 * probably includes panels (gnome).
5546 * Blah, doesn't work on KDE. */
5547 if (workarea[2] != window.width
5548 || workarea[3] != window.height) {
5562 static int cur_x, cur_y; /* current x and y for drawing */
5563 static int draw_mode; /* FG, BG or OUTLINE */
5564 static long current_color;
5567 static void text_size_updater(char *s)
5571 /* get string widths and skip specials */
5574 if (*p == SPECIAL_CHAR) {
5576 w += get_string_width(s);
5579 if (specials[special_index].type == BAR
5580 || specials[special_index].type == GRAPH) {
5581 w += specials[special_index].width;
5582 if (specials[special_index].height > last_font_height) {
5583 last_font_height = specials[special_index].height;
5584 last_font_height += font_ascent();
5586 } else if (specials[special_index].type == OFFSET) {
5587 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5588 } else if (specials[special_index].type == VOFFSET) {
5589 last_font_height += specials[special_index].arg;
5590 } else if (specials[special_index].type == GOTO) {
5591 if (specials[special_index].arg >= 0)
5592 w += (int)specials[special_index].arg - cur_x;
5593 } else if (specials[special_index].type == TAB) {
5594 int start = specials[special_index].arg;
5595 int step = specials[special_index].width;
5596 if (!step || step < 0)
5598 w += step - (cur_x - text_start_x - start) % step;
5599 } else if (specials[special_index].type == FONT) {
5600 selected_font = specials[special_index].font_added;
5601 if (font_height() > last_font_height) {
5602 last_font_height = font_height();
5611 w += get_string_width(s);
5612 if (w > text_width) {
5615 if (text_width > maximum_width && maximum_width) {
5616 text_width = maximum_width;
5619 text_height += last_font_height;
5620 last_font_height = font_height();
5624 static inline void set_foreground_color(long c)
5627 XSetForeground(display, window.gc, c);
5631 static void draw_string(const char *s)
5635 int i, i2, pos, width_of_s;
5638 width_of_s = get_string_width(s);
5639 if (out_to_console) {
5641 fflush(stdout); /* output immediately, don't buffer */
5643 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5644 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5645 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5649 snprintf(space, 2, " ");
5651 max = ((text_width - width_of_s) / get_string_width(space));
5654 * This code looks for tabs in the text and coverts them to spaces.
5655 * The trick is getting the correct number of spaces,
5656 * and not going over the window's size without forcing
5657 * the window larger.
5659 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5660 if (tmpstring1[i] == '\t') // 9 is ascii tab
5664 i2 < (8 - (1 + pos) % 8) && added <= max;
5667 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5668 fprintf(stderr,"buffer overrun detected\n");
5670 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5675 if (tmpstring1[i] != 9) {
5677 if ( pos > TEXT_BUFFER_SIZE-1 )
5678 fprintf(stderr,"buffer overrun detected\n");
5680 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5686 if (text_width == maximum_width) {
5687 /* this means the text is probably pushing the limit, so we'll chop it */
5688 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5689 tmpstring2[strlen(tmpstring2)-1] = '\0';
5699 c.pixel = current_color;
5700 XQueryColor(display, DefaultColormap(display, screen), &c);
5703 c2.color.red = c.red;
5704 c2.color.green = c.green;
5705 c2.color.blue = c.blue;
5706 c2.color.alpha = fonts[selected_font].font_alpha;
5708 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5709 cur_x, cur_y, (XftChar8 *) s,
5712 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5713 cur_x, cur_y, (XftChar8 *) s,
5719 XDrawString(display, window.drawable, window.gc,
5720 cur_x, cur_y, s, strlen(s));
5722 cur_x += width_of_s;
5724 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5727 long redmask, greenmask, bluemask;
5729 void set_up_gradient()
5732 colour_depth = DisplayPlanes(display, screen);
5736 if (colour_depth != 24 && colour_depth != 16) {
5737 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5743 for(i = (colour_depth / 3)-1; i>=0; i--) {
5745 greenmask |= 1 << i;
5748 if (colour_depth%3 == 1) {
5749 greenmask |= 1 << (colour_depth / 3);
5751 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5752 greenmask = greenmask << (colour_depth / 3);
5755 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 */
5757 int red1, green1, blue1; // first colour
5758 int red2, green2, blue2; // second colour
5759 int red3 = 0, green3 = 0, blue3 = 0; // difference
5760 short redshift = (2*colour_depth / 3 + colour_depth%3);
5761 short greenshift = (colour_depth / 3);
5762 red1 = (first_colour & redmask) >> redshift;
5763 green1 = (first_colour & greenmask) >> greenshift;
5764 blue1 = first_colour & bluemask;
5765 red2 = (last_colour & redmask) >> redshift;
5766 green2 = (last_colour & greenmask) >> greenshift;
5767 blue2 = last_colour & bluemask;
5774 if (green1 > green2) {
5777 if (green1 < green2) {
5780 if (blue1 > blue2) {
5783 if (blue1 < blue2) {
5798 if (red1 > bluemask) {
5801 if (green1 > bluemask) {
5804 if (blue1 > bluemask) {
5807 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5811 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5812 if (colour_depth == 0) {
5815 int red1, green1, blue1; // first colour
5816 int red2, green2, blue2; // second colour
5817 long redshift = (2*colour_depth / 3 + colour_depth%3);
5818 long greenshift = (colour_depth / 3);
5819 int red3 = 0, green3 = 0, blue3 = 0; // difference
5820 red1 = (first_colour & redmask) >> redshift;
5821 green1 = (first_colour & greenmask) >> greenshift;
5822 blue1 = first_colour & bluemask;
5823 red2 = (last_colour & redmask) >> redshift;
5824 green2 = (last_colour & greenmask) >> greenshift;
5825 blue2 = last_colour & bluemask;
5826 red3 = abs(red1 - red2);
5827 green3 = abs(green1 - green2);
5828 blue3 = abs(blue1 - blue2);
5837 static void draw_line(char *s)
5841 cur_x = text_start_x;
5842 cur_y += font_ascent();
5844 short font_h = font_height();
5846 /* find specials and draw stuff */
5849 if (*p == SPECIAL_CHAR) {
5852 /* draw string before special */
5859 switch (specials[special_index].type) {
5860 case HORIZONTAL_LINE:
5863 specials[special_index].height;
5864 int mid = font_ascent() / 2;
5865 w = text_start_x + text_width -
5868 XSetLineAttributes(display,
5873 XDrawLine(display, window.drawable,
5884 specials[special_index].height;
5886 specials[special_index].arg;
5887 int mid = font_ascent() / 2;
5888 char ss[2] = { s, s };
5889 w = text_start_x + text_width -
5892 XSetLineAttributes(display,
5897 XSetDashes(display, window.gc, 0,
5899 XDrawLine(display, window.drawable,
5909 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5913 specials[special_index].height;
5915 specials[special_index].arg;
5916 int by = cur_y - (font_ascent() / 2) - 1;
5917 if (h < font_height()) {
5920 w = specials[special_index].width;
5923 text_width - cur_x - 1;
5927 XSetLineAttributes(display,
5933 XDrawRectangle(display,
5937 XFillRectangle(display,
5941 w * bar_usage / 255,
5943 if (specials[special_index].
5945 && specials[special_index].
5949 [special_index].height;
5956 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5960 specials[special_index].height;
5961 unsigned long last_colour = current_color;
5962 int by = cur_y - (font_ascent()/2) - 1;
5963 if (h < font_height()) {
5966 w = specials[special_index].width;
5968 w = text_start_x + text_width - cur_x - 1;
5971 if (draw_graph_borders) {
5972 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5973 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5975 XSetLineAttributes(display,
5982 int gradient_size = 0;
5983 float gradient_factor = 0;
5984 float gradient_update = 0;
5985 unsigned long tmpcolour = current_color;
5986 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5987 tmpcolour = specials[special_index].last_colour;
5988 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5989 gradient_factor = (float)gradient_size / (w - 2);
5991 for (i = w - 2; i > -1; i--) {
5992 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5993 XSetForeground(display, window.gc, tmpcolour);
5994 gradient_update += gradient_factor;
5995 while (gradient_update > 0) {
5996 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
6000 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
6003 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 */
6005 if (specials[special_index].
6007 && specials[special_index].
6011 [special_index].height;
6013 /* if (draw_mode == BG) {
6014 set_foreground_color(default_bg_color);
6016 else if (draw_mode == OUTLINE) {
6017 set_foreground_color(default_out_color);
6019 set_foreground_color(default_fg_color);
6021 set_foreground_color(last_colour);
6027 int old = font_ascent();
6028 cur_y -= font_ascent();
6029 selected_font = specials[special_index].font_added;
6030 if (cur_y + font_ascent() < cur_y + old) {
6033 cur_y += font_ascent();
6039 if (draw_mode == FG)
6040 set_foreground_color(specials
6046 if (draw_mode == BG)
6047 set_foreground_color(specials
6053 if (draw_mode == OUTLINE)
6054 set_foreground_color(specials
6060 w += specials[special_index].arg;
6064 cur_y += specials[special_index].arg;
6068 if (specials[special_index].arg >= 0)
6069 cur_x = (int)specials[special_index].arg;
6074 int start = specials[special_index].arg;
6075 int step = specials[special_index].width;
6076 if (!step || step < 0)
6078 w = step - (cur_x - text_start_x - start) % step;
6084 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
6085 /*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);*/
6086 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6087 cur_x = pos_x - specials[special_index].arg;
6094 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
6095 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
6096 /*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);*/
6098 specials[special_index].arg)
6101 [special_index].arg;
6118 if (cur_y_add > 0) {
6120 cur_y -= font_descent();
6125 cur_y += font_descent();
6129 static void draw_text()
6132 cur_y = text_start_y;
6135 if (draw_borders && border_width > 0) {
6136 unsigned int b = (border_width + 1) / 2;
6138 if (stippled_borders) {
6140 { stippled_borders, stippled_borders };
6141 XSetLineAttributes(display, window.gc,
6142 border_width, LineOnOffDash,
6143 CapButt, JoinMiter);
6144 XSetDashes(display, window.gc, 0, ss, 2);
6146 XSetLineAttributes(display, window.gc,
6147 border_width, LineSolid,
6148 CapButt, JoinMiter);
6151 XDrawRectangle(display, window.drawable, window.gc,
6152 text_start_x - border_margin + b,
6153 text_start_y - border_margin + b,
6154 text_width + border_margin * 2 - 1 - b * 2,
6155 text_height + border_margin * 2 - 1 -
6162 for_each_line(text_buffer, draw_line);
6165 static void draw_stuff()
6169 if (draw_shades && !draw_outline) {
6172 set_foreground_color(default_bg_color);
6182 for (i = -1; i < 2; i++)
6183 for (j = -1; j < 2; j++) {
6184 if (i == 0 && j == 0)
6188 set_foreground_color(default_out_color);
6189 draw_mode = OUTLINE;
6196 set_foreground_color(default_fg_color);
6204 swap.swap_window = window.window;
6205 swap.swap_action = XdbeBackground;
6206 XdbeSwapBuffers(display, &swap, 1);
6212 static void clear_text(int exposures)
6216 return; /* The swap action is XdbeBackground, which clears */
6220 /* there is some extra space for borders and outlines */
6221 XClearArea(display, window.window,
6222 text_start_x - border_margin - 1,
6223 text_start_y - border_margin - 1,
6224 text_width + border_margin * 2 + 2,
6225 text_height + border_margin * 2 + 2,
6226 exposures ? True : 0);
6231 static int need_to_update;
6233 /* update_text() generates new text and clears old text area */
6234 static void update_text()
6243 static void main_loop()
6245 #ifdef SIGNAL_BLOCKING
6246 sigset_t newmask, oldmask;
6248 sigemptyset(&newmask);
6249 sigaddset(&newmask,SIGINT);
6250 sigaddset(&newmask,SIGTERM);
6251 sigaddset(&newmask,SIGUSR1);
6255 Region region = XCreateRegion();
6257 int event_base, error_base;
6258 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6259 ERR("Xdamage extension unavailable");
6261 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6262 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6263 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6264 #endif /* HAVE_XDAMAGE */
6268 while (total_run_times == 0 || info.looped < total_run_times) {
6271 #ifdef SIGNAL_BLOCKING
6272 /* block signals. we will inspect for pending signals later */
6273 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6274 CRIT_ERR("unable to sigprocmask()");
6280 /* wait for X event or timeout */
6282 if (!XPending(display)) {
6287 update_interval - (get_time() -
6293 tv.tv_sec = (long) t;
6294 tv.tv_usec = (long) (t * 1000000) % 1000000;
6296 FD_SET(ConnectionNumber(display), &fdsr);
6299 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6302 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6307 ERR("can't select(): %s",
6318 if (need_to_update) {
6320 int wx = window.x, wy = window.y;
6328 /* resize window if it isn't right size */
6330 (text_width + border_margin * 2 + 1 !=
6332 || text_height + border_margin * 2 + 1 !=
6336 border_margin * 2 + 1;
6339 border_margin * 2 + 1;
6340 XResizeWindow(display,
6345 set_transparent_background(window.window);
6349 /* move window if it isn't in right position */
6352 || window.y != wy)) {
6353 XMoveWindow(display, window.window,
6354 window.x, window.y);
6364 r.x = text_start_x - border_margin;
6365 r.y = text_start_y - border_margin;
6366 r.width = text_width + border_margin * 2;
6367 r.height = text_height + border_margin * 2;
6368 XUnionRectWithRegion(&r, region, region);
6373 /* handle X events */
6375 while (XPending(display)) {
6377 XNextEvent(display, &ev);
6384 r.width = ev.xexpose.width;
6385 r.height = ev.xexpose.height;
6386 XUnionRectWithRegion(&r, region,
6392 case ReparentNotify:
6393 /* set background to ParentRelative for all parents */
6395 set_transparent_background(window.
6400 case ConfigureNotify:
6402 /* if window size isn't what expected, set fixed size */
6403 if (ev.xconfigure.width !=
6405 || ev.xconfigure.height !=
6407 if (window.width != 0
6408 && window.height != 0)
6411 /* clear old stuff before screwing up size and pos */
6417 if (XGetWindowAttributes(display, window.window, &attrs)) {
6432 border_margin * 2 - 1;
6435 border_margin * 2 - 1;
6436 if (text_width > maximum_width && maximum_width > 0)
6437 text_width = maximum_width;
6440 /* if position isn't what expected, set fixed pos, total_updates
6441 * avoids setting fixed_pos when window is set to weird locations
6443 /*if (total_updates >= 2 this is broken
6445 && (window.x != ev.xconfigure.x
6448 && (ev.xconfigure.x != 0
6449 || ev.xconfigure.y != 0)) {
6459 /* if an ordinary window with decorations */
6460 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6462 /* allow conky to hold input focus.*/
6467 /* forward the click to the desktop window */
6468 XUngrabPointer(display, ev.xbutton.time);
6469 ev.xbutton.window = window.desktop;
6470 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6471 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6479 /* if an ordinary window with decorations */
6480 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6482 /* allow conky to hold input focus.*/
6487 /* forward the release to the desktop window */
6488 ev.xbutton.window = window.desktop;
6489 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6498 if (ev.type == event_base + XDamageNotify) {
6499 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6500 XFixesSetRegion(display, part, &dev->area, 1);
6501 XFixesUnionRegion(display, region2, region2, part);
6503 #endif /* HAVE_XDAMAGE */
6508 XDamageSubtract(display, damage, region2, None);
6509 XFixesSetRegion(display, region2, 0, 0);
6510 #endif /* HAVE_XDAMAGE */
6512 /* XDBE doesn't seem to provide a way to clear the back buffer without
6513 * interfering with the front buffer, other than passing XdbeBackground
6514 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6515 * redraw the text even if it wasn't part of the exposed area. OTOH,
6516 * if we're not going to call draw_stuff at all, then no swap happens
6517 * and we can safely do nothing.
6520 if (!XEmptyRegion(region)) {
6524 r.x = text_start_x - border_margin;
6525 r.y = text_start_y - border_margin;
6526 r.width = text_width + border_margin * 2;
6527 r.height = text_height + border_margin * 2;
6528 XUnionRectWithRegion(&r, region, region);
6531 XSetRegion(display, window.gc, region);
6534 XftDrawSetClip(window.xftdraw, region);
6540 XDestroyRegion(region);
6541 region = XCreateRegion();
6545 #ifdef SIGNAL_BLOCKING
6546 /* unblock signals of interest and let handler fly */
6547 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6548 CRIT_ERR("unable to sigprocmask()");
6551 switch(g_signal_pending) {
6554 ERR("received SIGUSR1. reloading the config file.");
6561 ERR("received SIGINT or SIGTERM to terminate. bye!");
6564 XDestroyRegion(region);
6567 return; /* return from main_loop */
6572 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6573 * but didn't write any code to deal with it. if you don't want to
6574 * handle a signal, don't set a handler on it in the first place. */
6575 if (g_signal_pending)
6576 ERR("ignoring signal (%d)", g_signal_pending);
6583 #if defined(X11) && defined(HAVE_XDAMAGE)
6584 XDamageDestroy(display, damage);
6585 XFixesDestroyRegion(display, region2);
6586 XFixesDestroyRegion(display, part);
6587 XDestroyRegion(region);
6589 #endif /* X11 && HAVE_XDAMAGE */
6592 static void load_config_file(const char *);
6594 /* reload the config file */
6595 void reload_config(void)
6597 timed_thread_destroy_registered_threads ();
6599 if (info.cpu_usage) {
6600 free(info.cpu_usage);
6601 info.cpu_usage = NULL;
6610 if (info.mpd.title) {
6611 free(info.mpd.title);
6614 if (info.mpd.artist) {
6615 free(info.mpd.artist);
6616 info.mpd.artist = 0;
6618 if (info.mpd.album) {
6619 free(info.mpd.album);
6622 if (info.mpd.random) {
6623 free(info.mpd.random);
6624 info.mpd.random = 0;
6626 if (info.mpd.repeat) {
6627 free(info.mpd.repeat);
6628 info.mpd.repeat = 0;
6630 if (info.mpd.track) {
6631 free(info.mpd.track);
6634 if (info.mpd.name) {
6635 free(info.mpd.name);
6638 if (info.mpd.file) {
6639 free(info.mpd.file);
6642 if (info.mpd.status) {
6643 free(info.mpd.status);
6644 info.mpd.status = 0;
6652 #ifdef TCP_PORT_MONITOR
6653 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6656 if (current_config) {
6658 load_config_file(current_config);
6660 /* re-init specials array */
6661 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6662 ERR("failed to realloc specials array");
6667 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6670 #ifdef TCP_PORT_MONITOR
6671 info.p_tcp_port_monitor_collection = NULL;
6674 if (create_audacious_thread() !=0)
6675 CRIT_ERR("unable to create audacious thread!");
6676 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6678 extract_variable_text(text);
6687 timed_thread_destroy_registered_threads ();
6689 if (info.cpu_usage) {
6690 free(info.cpu_usage);
6691 info.cpu_usage = NULL;
6696 XdbeDeallocateBackBufferName(display, window.back_buffer);
6702 XDestroyWindow(display, window.window);
6703 XClearWindow(display, RootWindow(display, screen));
6709 XClearWindow(display, RootWindow(display, screen));
6714 XFreeGC(display, window.gc);
6718 free_text_objects(text_object_count, text_objects);
6719 text_object_count = 0;
6720 text_objects = NULL;
6722 if (text != original_text)
6725 free(current_config);
6726 free(current_mail_spool);
6728 #ifdef TCP_PORT_MONITOR
6729 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6730 info.p_tcp_port_monitor_collection = NULL;
6738 for(i=0;i<special_count;i++)
6739 if(specials[i].type == GRAPH)
6740 free(specials[i].graph);
6746 static int string_to_bool(const char *s)
6750 if (strcasecmp(s, "yes") == 0)
6752 if (strcasecmp(s, "true") == 0)
6754 if (strcasecmp(s, "1") == 0)
6759 static enum alignment string_to_alignment(const char *s)
6761 if (strcasecmp(s, "top_left") == 0)
6763 else if (strcasecmp(s, "top_right") == 0)
6765 else if (strcasecmp(s, "bottom_left") == 0)
6767 else if (strcasecmp(s, "bottom_right") == 0)
6768 return BOTTOM_RIGHT;
6769 else if (strcasecmp(s, "tl") == 0)
6771 else if (strcasecmp(s, "tr") == 0)
6773 else if (strcasecmp(s, "bl") == 0)
6775 else if (strcasecmp(s, "br") == 0)
6776 return BOTTOM_RIGHT;
6777 else if (strcasecmp(s, "none") == 0)
6784 static void set_default_configurations(void)
6786 fork_to_background = 0;
6787 total_run_times = 0;
6788 info.cpu_avg_samples = 2;
6789 info.net_avg_samples = 2;
6794 strcpy(info.mpd.host, "localhost");
6795 info.mpd.port = 6600;
6796 info.mpd.status = NULL;
6797 info.mpd.artist = NULL;
6798 info.mpd.album = NULL;
6799 info.mpd.title = NULL;
6800 info.mpd.random = NULL;
6801 info.mpd.track = NULL;
6802 info.mpd.name = NULL;
6803 info.mpd.file = NULL;
6806 info.xmms2.artist = NULL;
6807 info.xmms2.album = NULL;
6808 info.xmms2.title = NULL;
6809 info.xmms2.genre = NULL;
6810 info.xmms2.comment = NULL;
6811 info.xmms2.decoder = NULL;
6812 info.xmms2.transport = NULL;
6813 info.xmms2.url = NULL;
6814 info.xmms2.status = NULL;
6823 default_fg_color = WhitePixel(display, screen);
6824 default_bg_color = BlackPixel(display, screen);
6825 default_out_color = BlackPixel(display, screen);
6826 color0 = default_fg_color;
6827 color1 = default_fg_color;
6828 color2 = default_fg_color;
6829 color3 = default_fg_color;
6830 color4 = default_fg_color;
6831 color5 = default_fg_color;
6832 color6 = default_fg_color;
6833 color7 = default_fg_color;
6834 color8 = default_fg_color;
6835 color9 = default_fg_color;
6838 draw_graph_borders = 1;
6840 set_first_font("6x10");
6848 window.type=TYPE_NORMAL;
6850 strcpy(window.class_name, "Conky");
6852 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6854 stippled_borders = 0;
6857 text_alignment = BOTTOM_LEFT;
6860 free(current_mail_spool);
6863 variable_substitute(MAIL_FILE, buf, 256);
6865 current_mail_spool = strdup(buf);
6869 update_interval = 10.0;
6870 stuff_in_upper_case = 0;
6872 #ifdef TCP_PORT_MONITOR
6873 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6877 static void load_config_file(const char *f)
6879 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6883 set_default_configurations();
6889 char buf[256], *p, *p2, *name, *value;
6891 if (fgets(buf, 256, fp) == NULL)
6896 /* break at comment */
6897 p2 = strchr(p, '#');
6902 while (*p && isspace((int) *p))
6905 continue; /* empty line */
6911 while (*p2 && !isspace((int) *p2))
6914 *p2 = '\0'; /* break at name's end */
6921 while (*p && isspace((int) *p))
6926 p2 = value + strlen(value);
6927 while (isspace((int) *(p2 - 1)))
6933 #define CONF2(a) if (strcasecmp(name, a) == 0)
6934 #define CONF(a) else CONF2(a)
6935 #define CONF3(a,b) \
6936 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6940 CONF2("alignment") {
6942 int a = string_to_alignment(value);
6950 CONF("background") {
6951 fork_to_background = string_to_bool(value);
6955 CONF2("background") {
6956 fork_to_background = string_to_bool(value);
6960 CONF("border_margin") {
6962 border_margin = strtol(value, 0, 0);
6966 CONF("border_width") {
6968 border_width = strtol(value, 0, 0);
6974 color0 = get_x11_color(value);
6980 color1 = get_x11_color(value);
6986 color2 = get_x11_color(value);
6992 color3 = get_x11_color(value);
6998 color4 = get_x11_color(value);
7004 color5 = get_x11_color(value);
7010 color6 = get_x11_color(value);
7016 color7 = get_x11_color(value);
7022 color8 = get_x11_color(value);
7028 color9 = get_x11_color(value);
7032 CONF("default_color") {
7034 default_fg_color = get_x11_color(value);
7038 CONF3("default_shade_color", "default_shadecolor") {
7040 default_bg_color = get_x11_color(value);
7044 CONF3("default_outline_color", "default_outlinecolor") {
7046 default_out_color = get_x11_color(value);
7053 info.mail = parse_mail_args(IMAP, value);
7060 info.mail = parse_mail_args(POP3, value);
7068 strncpy(info.mpd.host, value, 127);
7074 info.mpd.port = strtol(value, 0, 0);
7075 if (info.mpd.port < 1
7076 || info.mpd.port > 0xffff)
7080 CONF("mpd_password") {
7082 strncpy(info.mpd.password, value, 127);
7087 CONF("music_player_interval") {
7089 info.music_player_interval = strtod(value, 0);
7094 CONF("sensor_device") {
7096 sensor_device = strtol(value, 0, 0);
7101 CONF("cpu_avg_samples") {
7103 cpu_avg_samples = strtol(value, 0, 0);
7104 if (cpu_avg_samples < 1
7105 || cpu_avg_samples > 14)
7114 CONF("net_avg_samples") {
7116 net_avg_samples = strtol(value, 0, 0);
7117 if (net_avg_samples < 1
7118 || net_avg_samples > 14)
7134 CONF("double_buffer") {
7135 use_xdbe = string_to_bool(value);
7139 CONF("override_utf8_locale") {
7140 utf8_mode = string_to_bool(value);
7143 CONF("draw_borders") {
7144 draw_borders = string_to_bool(value);
7146 CONF("draw_graph_borders") {
7147 draw_graph_borders = string_to_bool(value);
7149 CONF("draw_shades") {
7150 draw_shades = string_to_bool(value);
7152 CONF("draw_outline") {
7153 draw_outline = string_to_bool(value);
7156 CONF("out_to_console") {
7157 out_to_console = string_to_bool(value);
7159 CONF("use_spacer") {
7160 use_spacer = string_to_bool(value);
7165 use_xft = string_to_bool(value);
7169 set_first_font(value);
7174 if (value && font_count >= 0)
7175 fonts[0].font_alpha = atof(value)
7184 if (string_to_bool(value))
7185 ERR("Xft not enabled");
7188 /* xftfont silently ignored when no Xft */
7191 /* xftalpha is silently ignored when no Xft */
7196 set_first_font(value);
7205 gap_x = atoi(value);
7211 gap_y = atoi(value);
7216 CONF("mail_spool") {
7219 variable_substitute(value, buf, 256);
7223 if (current_mail_spool)
7224 free(current_mail_spool);
7225 current_mail_spool = strdup(buf);
7231 CONF("minimum_size") {
7234 (value, "%d %d", &minimum_width,
7235 &minimum_height) != 2)
7238 &minimum_width) != 1)
7243 CONF("maximum_width") {
7245 if (sscanf(value, "%d", &maximum_width) != 1)
7251 CONF("no_buffers") {
7252 no_buffers = string_to_bool(value);
7254 CONF("pad_percents") {
7255 pad_percents = atoi(value);
7259 CONF("own_window") {
7261 own_window = string_to_bool(value);
7265 CONF("own_window_class") {
7268 memset(window.class_name,0,sizeof(window.class_name));
7269 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7274 CONF("own_window_title") {
7277 memset(window.title,0,sizeof(window.title));
7278 strncpy(window.title, value, sizeof(window.title)-1);
7283 CONF("own_window_transparent") {
7285 set_transparent = string_to_bool(value);
7289 CONF("own_window_colour") {
7291 background_colour = get_x11_color(value);
7293 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7296 CONF("own_window_hints") {
7298 char *p_hint, *p_save;
7299 char delim[] = ", ";
7301 /* tokenize the value into individual hints */
7302 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7304 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7305 if (strncmp(p_hint,"undecorate",10) == 0)
7306 SET_HINT(window.hints,HINT_UNDECORATED);
7307 else if (strncmp(p_hint,"below",5) == 0)
7308 SET_HINT(window.hints,HINT_BELOW);
7309 else if (strncmp(p_hint,"above",5) == 0)
7310 SET_HINT(window.hints,HINT_ABOVE);
7311 else if (strncmp(p_hint,"sticky",6) == 0)
7312 SET_HINT(window.hints,HINT_STICKY);
7313 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7314 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7315 else if (strncmp(p_hint,"skip_pager",10) == 0)
7316 SET_HINT(window.hints,HINT_SKIP_PAGER);
7320 p_hint=strtok_r(NULL, delim, &p_save);
7322 while (p_hint!=NULL);
7327 CONF("own_window_type") {
7329 if (strncmp(value,"normal",6)==0)
7330 window.type = TYPE_NORMAL;
7331 else if (strncmp(value,"desktop",7)==0)
7332 window.type = TYPE_DESKTOP;
7333 else if (strncmp(value,"override",8)==0)
7334 window.type = TYPE_OVERRIDE;
7342 CONF("stippled_borders") {
7344 stippled_borders = strtol(value, 0, 0);
7346 stippled_borders = 4;
7350 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7353 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7355 CONF("update_interval") {
7357 update_interval = strtod(value, 0);
7360 if (info.music_player_interval == 0) {
7361 // default to update_interval
7362 info.music_player_interval = update_interval;
7365 CONF("total_run_times") {
7367 total_run_times = strtod(value, 0);
7372 stuff_in_upper_case = string_to_bool(value);
7374 CONF("max_specials") {
7376 max_specials = atoi(value);
7380 CONF("max_user_text") {
7382 max_user_text = atoi(value);
7386 CONF("text_buffer_size") {
7388 text_buffer_size = atoi(value);
7393 if (text != original_text)
7403 int l = strlen(text);
7404 if (fgets(buf, 256, fp) == NULL)
7407 realloc(text, l + strlen(buf)
7411 if (strlen(text) > max_user_text)
7415 text_lines = line + 1;
7418 #ifdef TCP_PORT_MONITOR
7419 CONF("max_port_monitor_connections")
7422 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7423 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7425 /* an error. use default, warn and continue. */
7426 tcp_port_monitor_args.max_port_monitor_connections =
7427 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7430 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7432 /* no error, just use default */
7433 tcp_port_monitor_args.max_port_monitor_connections =
7434 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7436 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7441 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7450 if (info.music_player_interval == 0) {
7451 // default to update_interval
7452 info.music_player_interval = update_interval;
7457 /* : means that character before that takes an argument */
7458 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7471 int main(int argc, char **argv)
7473 struct sigaction act, oact;
7476 memset(&info, 0, sizeof(info));
7478 #ifdef TCP_PORT_MONITOR
7479 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7482 /* handle command line parameters that don't change configs */
7487 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7488 *s) || ((s = getenv("LANG")) && *s)) {
7489 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7491 ERR("malloc failed");
7493 for (x = 0; x < strlen(s); x++) {
7494 temp[x] = tolower(s[x]);
7497 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7503 if (!setlocale(LC_CTYPE, "")) {
7504 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7508 int c = getopt(argc,
7519 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7520 * though free() does the NULL check itself;), then load optarg value */
7522 free(current_config);
7523 current_config = strdup(optarg);
7528 ("Usage: %s [OPTION]...\n"
7529 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7530 "window. Command line options will override configurations defined in config\n"
7533 " -c FILE config file to load instead of "
7536 " -d daemonize, fork to background\n"
7539 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7540 " -f FONT font to use\n"
7542 " -o create own window to draw\n"
7545 " -b double buffer (prevents flickering)\n"
7547 " -w WIN_ID window id to draw\n"
7548 " -x X x position\n"
7549 " -y Y y position\n"
7551 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7552 " -u SECS update interval\n"
7553 " -i NUM number of times to update Conky\n", argv[0]);
7557 window.window = strtol(optarg, 0, 0);
7566 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7570 /* load current_config or CONFIG_FILE */
7573 if (current_config == NULL) {
7574 /* load default config file */
7577 variable_substitute(CONFIG_FILE, buf, 256);
7580 current_config = strdup(buf);
7584 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7585 load_config_file(current_config);
7587 set_default_configurations();
7590 /* init specials array */
7591 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7592 ERR("failed to create specials array");
7595 if (current_mail_spool == NULL) {
7597 variable_substitute(MAIL_FILE, buf, 256);
7600 current_mail_spool = strdup(buf);
7604 /* handle other command line arguments */
7606 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7607 optind = optreset = 1;
7612 #if defined(__FreeBSD__)
7613 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7614 O_RDONLY, "kvm_open")) == NULL)
7615 CRIT_ERR( "cannot read kvm");
7619 int c = getopt(argc,
7627 fork_to_background = 1;
7632 set_first_font(optarg);
7635 text_alignment = string_to_alignment(optarg);
7650 if (text != original_text)
7652 text = strdup(optarg);
7653 convert_escapes(text);
7657 update_interval = strtod(optarg, 0);
7658 if (info.music_player_interval == 0) {
7659 // default to update_interval
7660 info.music_player_interval = update_interval;
7665 total_run_times = strtod(optarg, 0);
7669 gap_x = atoi(optarg);
7673 gap_y = atoi(optarg);
7687 /* generate text and get initial size */
7688 extract_variable_text(text);
7689 if (text != original_text) {
7694 if (fork_to_background) {
7698 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7704 fprintf(stderr,"\n"); fflush(stderr);
7708 /* parent process */
7709 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7716 update_text_area(); /* to get initial size of the window */
7720 text_width + border_margin * 2 + 1,
7721 text_height + border_margin * 2 + 1,
7722 set_transparent, background_colour, argv, argc);
7725 update_text_area(); /* to position text/window on screen */
7730 if (own_window && !fixed_pos) {
7731 XMoveWindow(display, window.window, window.x, window.y);
7734 set_transparent_background(window.window);
7745 /* Set signal handlers */
7746 act.sa_handler = signal_handler;
7747 sigemptyset(&act.sa_mask);
7750 act.sa_flags |= SA_RESTART;
7753 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7754 sigaction(SIGUSR1,&act,&oact) < 0 ||
7755 sigaction(SIGTERM,&act,&oact) < 0 )
7757 ERR("error setting signal handler: %s", strerror(errno) );
7761 if (create_audacious_thread() !=0)
7762 CRIT_ERR("unable to create audacious thread!");
7763 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7774 #if defined(__FreeBSD__)
7781 void signal_handler(int sig)
7783 /* signal handler is light as a feather, as it should be.
7784 * we will poll g_signal_pending with each loop of conky
7785 * and do any signal processing there, NOT here. */
7786 g_signal_pending=sig;