2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
26 #include <X11/Xutil.h>
28 #include <X11/extensions/Xdamage.h>
34 #include <sys/types.h>
36 #include <netinet/in.h>
46 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
49 #define CONFIG_FILE "$HOME/.conkyrc"
50 #define MAIL_FILE "$MAIL"
51 #define MAX_IF_BLOCK_DEPTH 5
53 /* #define SIGNAL_BLOCKING */
54 #undef SIGNAL_BLOCKING
56 static void print_version()
58 printf("Conky %s compiled %s for %s\n",
59 VERSION, BUILD_DATE, BUILD_ARCH);
62 "\nCompiled in features:\n\n"
66 " * Xdamage extension\n"
67 # endif /* HAVE_XDAMAGE */
69 " * Xdbe extension (double buffer)\n"
70 # endif /* HAVE_XDBE */
76 "\n Music detection:\n"
79 #endif /* AUDACIOUS */
89 "\n General features:\n"
93 #ifdef TCP_PORT_MONITOR
95 #endif /* TCP_PORT_MONITOR */
107 static int text_start_x, text_start_y; /* text start position in window */
108 static int text_width, text_height;
123 char name[TEXT_BUFFER_SIZE];
133 static int selected_font = 0;
134 static int font_count = -1;
135 struct font_list *fonts = NULL;
139 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
140 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
141 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
142 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
146 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
147 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
148 #define font_descent() fonts[selected_font].font->max_bounds.descent
152 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
155 static void set_font();
157 int addfont(const char *data_in)
159 if (font_count > MAX_FONTS) {
160 CRIT_ERR("you don't need that many fonts, sorry.");
163 if (font_count == 0) {
167 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
171 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
173 CRIT_ERR("realloc in addfont");
175 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
176 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
178 fonts[font_count].font_alpha = 0xffff;
181 CRIT_ERR("Oops...looks like something overflowed in addfont().");
186 void set_first_font(const char *data_in)
188 if (font_count < 0) {
189 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
194 if (strlen(data_in) > 1) {
195 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
197 fonts[0].font_alpha = 0xffff;
205 for (i=0;i<=font_count;i++) {
208 XftFontClose(display, fonts[i].xftfont);
212 XFreeFont(display, fonts[i].font);
219 set_first_font("6x10");
223 static void load_fonts()
226 for (i=0; i <= font_count; i++) {
230 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
231 XftFontClose(display, fonts[i].xftfont);
233 if ((fonts[i].xftfont =
234 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
237 ERR("can't load Xft font '%s'", fonts[i].name);
238 if ((fonts[i].xftfont =
239 XftFontOpenName(display, screen,
240 "courier-12")) != NULL)
243 ERR("can't load Xft font '%s'", "courier-12");
245 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
246 CRIT_ERR("can't load font '%s'", "fixed");
253 /* load normal font */
254 /* if (fonts[i].font != NULL)
255 XFreeFont(display, fonts[i].font);*/
257 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
258 ERR("can't load font '%s'", fonts[i].name);
259 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
260 CRIT_ERR("can't load font '%s'", "fixed");
261 printf("loaded fixed?\n");
269 /* default config file */
270 static char *current_config;
272 /* set to 1 if you want all text to be in uppercase */
273 static unsigned int stuff_in_upper_case;
275 /* Run how many times? */
276 static unsigned long total_run_times;
279 static int fork_to_background;
281 static int cpu_avg_samples, net_avg_samples;
285 /* Position on the screen */
286 static int text_alignment;
287 static int gap_x, gap_y;
290 static int draw_borders;
291 static int draw_graph_borders;
292 static int stippled_borders;
294 static int draw_shades, draw_outline;
296 static int border_margin, border_width;
298 static long default_fg_color, default_bg_color, default_out_color;
299 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
301 /* create own window or draw stuff to root? */
302 static int set_transparent = 0;
306 static int own_window = 0;
307 static int background_colour = 0;
308 /* fixed size/pos is set if wm/user changes them */
309 static int fixed_size = 0, fixed_pos = 0;
312 static int minimum_width, minimum_height;
313 static int maximum_width;
318 static int sensor_device;
321 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
322 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
324 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
325 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
327 /* maximum size of individual text buffers, ie $exec buffer size */
328 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
331 #define CODEPAGE_LENGTH 20
334 char iconv_converting;
335 static iconv_t **iconv_cd = 0;
337 int register_iconv(iconv_t *new_iconv)
340 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
342 iconv_cd = malloc(sizeof(iconv_t *));
345 CRIT_ERR("Out of memory");
347 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
348 if (!iconv_cd[iconv_count]) {
349 CRIT_ERR("Out of memory");
351 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
356 void free_iconv(void)
360 for (i = iconv_count; i < 0; i++) {
376 /* no buffers in used memory? */
379 /* pad percentages to decimals? */
380 static int pad_percents = 0;
382 #ifdef TCP_PORT_MONITOR
383 tcp_port_monitor_args_t tcp_port_monitor_args;
386 /* Text that is shown */
387 static char original_text[] =
388 "$nodename - $sysname $kernel on $machine\n"
390 "${color grey}Uptime:$color $uptime\n"
391 "${color grey}Frequency (in MHz):$color $freq\n"
392 "${color grey}Frequency (in GHz):$color $freq_g\n"
393 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
394 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
395 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
396 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
398 "${color grey}File systems:\n"
399 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
400 "${color grey}Networking:\n"
401 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
404 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
405 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
408 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
409 "Progress: $xmms2_bar\n"
411 "${color grey}Name PID CPU% MEM%\n"
412 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
413 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
414 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
415 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
416 "${tail /var/log/Xorg.0.log 3}";
418 static char *text = original_text;
421 static int total_updates;
424 static int blockdepth = 0;
425 static int if_jumped = 0;
426 static int blockstart[MAX_IF_BLOCK_DEPTH];
428 int check_mount(char *s)
430 #if defined(__linux__)
432 FILE *mtab = fopen("/etc/mtab", "r");
434 char buf1[256], buf2[128];
435 while (fgets(buf1, 256, mtab)) {
436 sscanf(buf1, "%*s %128s", buf2);
437 if (!strcmp(s, buf2)) {
444 ERR("Could not open mtab");
447 #elif defined(__FreeBSD__)
448 struct statfs *mntbuf;
451 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
452 for (i = mntsize - 1; i >= 0; i--)
453 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
461 int check_contains(char *f, char *s)
464 FILE *where = fopen(f, "r");
466 char buf1[256], buf2[256];
467 while (fgets(buf1, 256, where)) {
468 sscanf(buf1, "%255s", buf2);
469 if (strstr(buf2, s)) {
476 ERR("Could not open the file");
483 static inline int calc_text_width(const char *s, int l)
489 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
491 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
497 return XTextWidth(fonts[selected_font].font, s, l);
502 /* formatted text to render on screen, generated in generate_text(),
503 * drawn in draw_stuff() */
505 static char text_buffer[TEXT_BUFFER_SIZE * 4];
507 /* special stuff in text_buffer */
509 #define SPECIAL_CHAR '\x01'
538 unsigned long first_colour; // for graph gradient
539 unsigned long last_colour;
542 /* create specials array on heap instead of stack with introduction of max_specials */
543 static struct special_t *specials = NULL;
545 static unsigned int special_count;
547 static unsigned int special_index; /* used when drawing */
550 #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? */
552 static struct special_t *new_special(char *buf, int t)
554 if (special_count >= max_specials)
555 CRIT_ERR("too many special things in text");
557 buf[0] = SPECIAL_CHAR;
559 specials[special_count].type = t;
560 return &specials[special_count++];
563 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
566 unsigned int count = 0;
567 static char buf[BUFSZ];
568 long orig_pos = ftell(fp);
570 long buf_size = BUFSZ;
571 char* cur_found = NULL;
572 while(count < step) {
573 if(cur_found == NULL) {
574 buf_size = fread(buf, 1, buf_size, fp);
577 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
578 if(cur_found != NULL) {
579 buf_pos = cur_found-buf+1;
588 ret = ftell(fp) - buf_size + buf_pos - 1;
589 fseek(fp, orig_pos, SEEK_SET);
596 memrchr (const void *buffer, int c, size_t n)
598 const unsigned char *p = buffer;
600 for (p += n; n ; n--)
606 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
609 unsigned int count = 0;
610 static char buf[BUFSZ];
611 long orig_pos = ftell(fp);
613 long file_pos = orig_pos;
614 long buf_size = BUFSZ;
616 while(count < step) {
618 if(file_pos > BUFSZ) {
619 fseek(fp, file_pos-BUFSZ, SEEK_SET);
623 fseek(fp, 0, SEEK_SET);
625 file_pos = ftell(fp);
626 buf_pos = fread(buf, 1, buf_size, fp);
633 if(cur_found != NULL) {
634 buf_pos = cur_found-buf;
643 fseek(fp, orig_pos, SEEK_SET);
645 ret = file_pos + buf_pos;
650 static void new_bar(char *buf, int w, int h, int usage)
652 struct special_t *s = new_special(buf, BAR);
653 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
658 static const char *scan_bar(const char *args, int *w, int *h)
660 *w = 0; /* zero width means all space that is available */
662 /* bar's argument is either height or height,width */
665 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
666 sscanf(args, "%d %n", h, &n);
673 static char *scan_font(const char *args)
675 if (args && sizeof(args) < 127) {
682 static void new_font(char *buf, char * args) {
684 struct special_t *s = new_special(buf, FONT);
685 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
686 int tmp = selected_font;
687 selected_font = s->font_added = addfont(args);
692 struct special_t *s = new_special(buf, FONT);
693 int tmp = selected_font;
694 selected_font = s->font_added = 0;
701 inline void graph_append(struct special_t *graph, double f)
703 if (!graph->scaled && f > graph->graph_scale) {
704 f = graph->graph_scale;
708 graph->graph_scale = 1;
710 graph->graph[0] = f; /* add new data */
711 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
712 graph->graph[i] = graph->graph[i - 1];
713 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
714 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
719 short colour_depth = 0;
720 void set_up_gradient();
722 /* precalculated: 31/255, and 63/255 */
723 #define CONST_8_TO_5_BITS 0.12156862745098
724 #define CONST_8_TO_6_BITS 0.247058823529412
726 /* adjust color values depending on color depth*/
727 static unsigned int adjust_colors(unsigned int color)
730 if (colour_depth == 0) {
733 if (colour_depth == 16) {
734 r = (color & 0xff0000) >> 16;
735 g = (color & 0xff00) >> 8;
737 color = (int)(r * CONST_8_TO_5_BITS) << 11;
738 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
739 color |= (int)(b * CONST_8_TO_5_BITS);
744 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
746 struct special_t *s = new_special(buf, GRAPH);
748 if (s->graph == NULL) {
749 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
750 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
752 s->graph_width = MAX_GRAPH_DEPTH - 2;
754 s->graph = malloc(s->graph_width * sizeof(double));
755 memset(s->graph, 0, s->graph_width * sizeof(double));
756 s->graph_scale = 100;
759 s->first_colour = adjust_colors(first_colour);
760 s->last_colour = adjust_colors(second_colour);
767 s->graph_width = s->width - 2; // subtract 2 for rectangle around
772 s->graph_scale = scale;
779 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
781 *w = 0; /* zero width means all space that is available */
785 /* graph's argument is either height or height,width */
787 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
788 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
790 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
792 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
795 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
799 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
802 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
806 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
809 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
813 if (sscanf(args, "%d,%d", h, w) < 2) {
816 sscanf(args, "%*s %d,%d", h, w);
822 static inline void new_hr(char *buf, int a)
824 new_special(buf, HORIZONTAL_LINE)->height = a;
827 static inline void new_stippled_hr(char *buf, int a, int b)
829 struct special_t *s = new_special(buf, STIPPLED_HR);
834 static inline void new_fg(char *buf, long c)
836 new_special(buf, FG)->arg = c;
839 static inline void new_bg(char *buf, long c)
841 new_special(buf, BG)->arg = c;
844 static inline void new_outline(char *buf, long c)
846 new_special(buf, OUTLINE)->arg = c;
849 static inline void new_offset(char *buf, long c)
851 new_special(buf, OFFSET)->arg = c;
854 static inline void new_voffset(char *buf, long c)
856 new_special(buf, VOFFSET)->arg = c;
859 static inline void new_alignr(char *buf, long c)
861 new_special(buf, ALIGNR)->arg = c;
864 static inline void new_alignc(char *buf, long c)
866 new_special(buf, ALIGNC)->arg = c;
869 static inline void new_goto(char *buf, long c)
871 new_special(buf, GOTO)->arg = c;
874 static inline void new_tab(char *buf, int a, int b) {
875 struct special_t *s = new_special(buf, TAB);
880 /* quite boring functions */
882 static inline void for_each_line(char *b, void (*f) (char *))
886 for (ps = b, pe = b; *pe; pe++) {
899 static void convert_escapes(char *buf)
901 char *p = buf, *s = buf;
917 /* converts from bytes to human readable format (k, M, G, T) */
918 static void human_readable(long long a, char *buf, int size)
920 // Strange conditional due to possible overflows
921 if(a / 1024 / 1024 / 1024.0 > 1024.0){
922 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
924 else if (a >= 1024 * 1024 * 1024) {
925 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
927 else if (a >= 1024 * 1024) {
928 double m = (a / 1024) / 1024.0;
930 snprintf(buf, size, "%.0fMiB", m);
932 snprintf(buf, size, "%.1fMiB", m);
933 } else if (a >= 1024)
934 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
936 snprintf(buf, size, "%LdB", a);
941 enum text_object_type {
975 OBJ_diskiograph_read,
976 OBJ_diskiograph_write,
1009 #if defined(__linux__)
1015 OBJ_i8k_left_fan_status,
1016 OBJ_i8k_right_fan_status,
1017 OBJ_i8k_left_fan_rpm,
1018 OBJ_i8k_right_fan_rpm,
1020 OBJ_i8k_buttons_status,
1028 #endif /* __linux__ */
1057 OBJ_running_processes,
1066 OBJ_temp1, /* i2c is used instead in these */
1086 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1088 OBJ_apm_battery_time,
1089 OBJ_apm_battery_life,
1090 #endif /* __FreeBSD__ */
1092 OBJ_obsd_sensors_temp,
1093 OBJ_obsd_sensors_fan,
1094 OBJ_obsd_sensors_volt,
1097 #endif /* __OpenBSD__ */
1126 OBJ_xmms2_transport,
1141 OBJ_audacious_status,
1142 OBJ_audacious_title,
1143 OBJ_audacious_length,
1144 OBJ_audacious_length_seconds,
1145 OBJ_audacious_position,
1146 OBJ_audacious_position_seconds,
1147 OBJ_audacious_bitrate,
1148 OBJ_audacious_frequency,
1149 OBJ_audacious_channels,
1150 OBJ_audacious_filename,
1151 OBJ_audacious_playlist_length,
1152 OBJ_audacious_playlist_position,
1163 #ifdef TCP_PORT_MONITOR
1174 OBJ_entropy_poolsize,
1178 struct text_object {
1182 unsigned int c, d, e;
1186 char *s; /* some string */
1187 int i; /* some integer */
1188 long l; /* some other integer */
1189 unsigned int sensor;
1190 struct net_stat *net;
1192 unsigned char loadavg[3];
1193 unsigned int cpu_index;
1194 struct mail_s *mail;
1202 char *tz; /* timezone variable */
1203 char *fmt; /* time display formatting */
1256 timed_thread *p_timed_thread;
1262 #ifdef TCP_PORT_MONITOR
1264 in_port_t port_range_begin; /* starting port to monitor */
1265 in_port_t port_range_end; /* ending port to monitor */
1266 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1267 int connection_index; /* 0 to n-1 connections. */
1280 struct text_object_list {
1281 unsigned int text_object_count;
1282 struct text_object *text_objects;
1285 static unsigned int text_object_count;
1286 static struct text_object *text_objects;
1287 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1289 #define MAXDATASIZE 1000
1293 struct mail_s* parse_mail_args(char type, const char *arg) {
1294 struct mail_s *mail;
1295 mail = malloc(sizeof(struct mail_s));
1296 memset(mail, 0, sizeof(struct mail_s));
1298 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1300 ERR("Scanning IMAP args failed");
1301 } else if (type == IMAP) {
1302 ERR("Scanning POP3 args failed");
1305 // see if password needs prompting
1306 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1307 int fp = fileno(stdin);
1308 struct termios term;
1309 tcgetattr(fp, &term);
1310 term.c_lflag &= ~ECHO;
1311 tcsetattr(fp, TCSANOW, &term);
1312 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1313 scanf("%128s", mail->pass);
1315 term.c_lflag |= ECHO;
1316 tcsetattr(fp, TCSANOW, &term);
1318 // now we check for optional args
1319 tmp = strstr(arg, "-i ");
1322 sscanf(tmp, "%f", &mail->interval);
1324 mail->interval = 300; // 5 minutes
1326 tmp = strstr(arg, "-p ");
1329 sscanf(tmp, "%lu", &mail->port);
1332 mail->port = 110; // default pop3 port
1333 } else if (type == IMAP) {
1334 mail->port = 143; // default imap port
1338 tmp = strstr(arg, "-f ");
1341 sscanf(tmp, "%s", mail->folder);
1343 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1346 tmp = strstr(arg, "-e ");
1350 if (tmp[0] == '\'') {
1351 len = strstr(tmp+1, "'") - tmp - 1;
1356 strncpy(mail->command, tmp+1, len);
1358 mail->command[0] = '\0';
1360 mail->p_timed_thread = NULL;
1364 void *imap_thread(struct mail_s* mail)
1366 int sockfd, numbytes;
1367 char recvbuf[MAXDATASIZE];
1368 char sendbuf[MAXDATASIZE];
1371 unsigned int old_unseen = UINT_MAX;
1372 unsigned int old_messages = UINT_MAX;
1373 struct stat stat_buf;
1375 struct sockaddr_in their_addr; // connector's address information
1376 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1377 herror("gethostbyname");
1382 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1384 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1387 goto next_iteration;
1390 their_addr.sin_family = AF_INET; // host byte order
1391 their_addr.sin_port = htons(mail->port); // short, network byte order
1392 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1393 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1396 (sockfd, (struct sockaddr *) &their_addr,
1397 sizeof(struct sockaddr)) == -1) {
1400 goto next_iteration;
1402 struct timeval timeout;
1405 timeout.tv_sec = 60; // 60 second timeout i guess
1406 timeout.tv_usec = 0;
1408 FD_SET(sockfd, &fdset);
1409 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1412 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1416 goto next_iteration;
1419 ERR("IMAP connection failed: timeout");
1421 goto next_iteration;
1423 recvbuf[numbytes] = '\0';
1424 if (strstr(recvbuf, "* OK") != recvbuf) {
1425 ERR("IMAP connection failed, probably not an IMAP server");
1427 goto next_iteration;
1429 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1430 strncat(sendbuf, mail->user,
1431 MAXDATASIZE - strlen(sendbuf) - 1);
1432 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1433 strncat(sendbuf, mail->pass,
1434 MAXDATASIZE - strlen(sendbuf) - 1);
1435 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1436 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1439 goto next_iteration;
1441 timeout.tv_sec = 60; // 60 second timeout i guess
1442 timeout.tv_usec = 0;
1444 FD_SET(sockfd, &fdset);
1445 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1448 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1452 goto next_iteration;
1455 recvbuf[numbytes] = '\0';
1456 if (strstr(recvbuf, "a1 OK") == NULL) {
1457 ERR("IMAP server login failed: %s", recvbuf);
1459 goto next_iteration;
1461 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1462 strncat(sendbuf, mail->folder,
1463 MAXDATASIZE - strlen(sendbuf) - 1);
1464 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1465 MAXDATASIZE - strlen(sendbuf) - 1);
1466 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1469 goto next_iteration;
1471 timeout.tv_sec = 60; // 60 second timeout i guess
1472 timeout.tv_usec = 0;
1474 FD_SET(sockfd, &fdset);
1475 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1478 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1482 goto next_iteration;
1485 recvbuf[numbytes] = '\0';
1486 if (strstr(recvbuf, "a2 OK") == NULL) {
1487 ERR("IMAP status failed: %s", recvbuf);
1489 goto next_iteration;
1491 // now we get the data
1492 reply = strstr(recvbuf, " (MESSAGES ");
1494 *strchr(reply, ')') = '\0';
1495 if (reply == NULL) {
1496 ERR("Error parsing IMAP response: %s", recvbuf);
1498 goto next_iteration;
1500 timed_thread_lock (mail->p_timed_thread);
1501 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1504 timed_thread_unlock (mail->p_timed_thread);
1506 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1507 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1510 goto next_iteration;
1512 timeout.tv_sec = 60; // 60 second timeout i guess
1513 timeout.tv_usec = 0;
1515 FD_SET(sockfd, &fdset);
1516 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1519 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1523 goto next_iteration;
1526 recvbuf[numbytes] = '\0';
1527 if (strstr(recvbuf, "a3 OK") == NULL) {
1528 ERR("IMAP logout failed: %s", recvbuf);
1530 goto next_iteration;
1532 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1533 if (system(mail->command) == -1) {
1538 old_unseen = mail->unseen;
1539 old_messages = mail->messages;
1541 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1542 /* if a valid socket, close it */
1544 if (timed_thread_test (mail->p_timed_thread))
1545 timed_thread_exit (mail->p_timed_thread);
1550 void *pop3_thread(struct mail_s *mail)
1552 int sockfd, numbytes;
1553 char recvbuf[MAXDATASIZE];
1554 char sendbuf[MAXDATASIZE];
1557 unsigned int old_unseen = UINT_MAX;
1558 struct stat stat_buf;
1560 struct sockaddr_in their_addr; // connector's address information
1561 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1562 herror("gethostbyname");
1567 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1569 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1572 goto next_iteration;
1575 their_addr.sin_family = AF_INET; // host byte order
1576 their_addr.sin_port = htons(mail->port); // short, network byte order
1577 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1578 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1581 (sockfd, (struct sockaddr *) &their_addr,
1582 sizeof(struct sockaddr)) == -1) {
1585 goto next_iteration;
1587 struct timeval timeout;
1590 timeout.tv_sec = 60; // 60 second timeout i guess
1591 timeout.tv_usec = 0;
1593 FD_SET(sockfd, &fdset);
1594 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1597 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1601 goto next_iteration;
1604 ERR("POP3 connection failed: timeout\n");
1606 goto next_iteration;
1608 recvbuf[numbytes] = '\0';
1609 if (strstr(recvbuf, "+OK ") != recvbuf) {
1610 ERR("POP3 connection failed, probably not a POP3 server");
1612 goto next_iteration;
1614 strncpy(sendbuf, "USER ", MAXDATASIZE);
1615 strncat(sendbuf, mail->user,
1616 MAXDATASIZE - strlen(sendbuf) - 1);
1617 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1618 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1619 perror("send USER");
1621 goto next_iteration;
1623 timeout.tv_sec = 60; // 60 second timeout i guess
1624 timeout.tv_usec = 0;
1626 FD_SET(sockfd, &fdset);
1627 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1630 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1632 perror("recv USER");
1634 goto next_iteration;
1637 recvbuf[numbytes] = '\0';
1638 if (strstr(recvbuf, "+OK ") == NULL) {
1639 ERR("POP3 server login failed: %s", recvbuf);
1641 goto next_iteration;
1643 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1644 strncat(sendbuf, mail->pass,
1645 MAXDATASIZE - strlen(sendbuf) - 1);
1646 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1647 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1648 perror("send PASS");
1650 goto next_iteration;
1652 timeout.tv_sec = 60; // 60 second timeout i guess
1653 timeout.tv_usec = 0;
1655 FD_SET(sockfd, &fdset);
1656 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1659 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1661 perror("recv PASS");
1663 goto next_iteration;
1666 recvbuf[numbytes] = '\0';
1667 if (strstr(recvbuf, "+OK ") == NULL) {
1668 ERR("POP3 server login failed: %s", recvbuf);
1670 goto next_iteration;
1672 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1673 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1674 perror("send STAT");
1676 goto next_iteration;
1678 timeout.tv_sec = 60; // 60 second timeout i guess
1679 timeout.tv_usec = 0;
1681 FD_SET(sockfd, &fdset);
1682 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1685 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1687 perror("recv STAT");
1689 goto next_iteration;
1692 recvbuf[numbytes] = '\0';
1693 if (strstr(recvbuf, "+OK ") == NULL) {
1694 ERR("POP3 status failed: %s", recvbuf);
1696 goto next_iteration;
1698 // now we get the data
1699 reply = recvbuf + 4;
1700 if (reply == NULL) {
1701 ERR("Error parsing POP3 response: %s", recvbuf);
1703 goto next_iteration;
1705 timed_thread_lock (mail->p_timed_thread);
1706 sscanf(reply, "%lu %lu", &mail->unseen,
1708 timed_thread_unlock (mail->p_timed_thread);
1710 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1711 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1712 perror("send QUIT");
1714 goto next_iteration;
1716 timeout.tv_sec = 60; // 60 second timeout i guess
1717 timeout.tv_usec = 0;
1719 FD_SET(sockfd, &fdset);
1720 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1723 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1725 perror("recv QUIT");
1727 goto next_iteration;
1730 recvbuf[numbytes] = '\0';
1731 if (strstr(recvbuf, "+OK") == NULL) {
1732 ERR("POP3 logout failed: %s", recvbuf);
1734 goto next_iteration;
1736 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1737 if (system(mail->command) == -1) {
1742 old_unseen = mail->unseen;
1744 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1745 /* if a valid socket, close it */
1747 if (timed_thread_test (mail->p_timed_thread))
1748 timed_thread_exit (mail->p_timed_thread);
1754 void *threaded_exec(struct text_object *obj) {
1756 char *p2 = obj->data.texeci.buffer;
1757 FILE *fp = popen(obj->data.texeci.cmd,"r");
1758 timed_thread_lock (obj->data.texeci.p_timed_thread);
1759 int n2 = fread(p2, 1, text_buffer_size, fp);
1762 if (n2 && p2[n2 - 1] == '\n') {
1766 if (*p2 == '\001') {
1771 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1772 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1773 timed_thread_exit (obj->data.texeci.p_timed_thread);
1778 static struct text_object *new_text_object_internal()
1780 struct text_object *obj = malloc(sizeof(struct text_object));
1781 memset(obj, 0, sizeof(struct text_object));
1785 static void free_text_objects(unsigned int count, struct text_object *objs)
1788 for (i = 0; i < count; i++) {
1789 switch (objs[i].type) {
1791 close(objs[i].data.i);
1794 close(objs[i].data.i);
1797 close(objs[i].data.i2c.fd);
1800 free(objs[i].data.s);
1803 free(objs[i].data.s);
1806 free(objs[i].data.tztime.tz);
1807 free(objs[i].data.tztime.fmt);
1810 free(objs[i].data.mboxscan.args);
1811 free(objs[i].data.mboxscan.output);
1816 case OBJ_imap_unseen:
1817 if (!objs[i].global_mode) {
1818 free(objs[i].data.mail);
1821 case OBJ_imap_messages:
1822 if (!objs[i].global_mode) {
1823 free(objs[i].data.mail);
1829 case OBJ_pop3_unseen:
1830 if (!objs[i].global_mode) {
1831 free(objs[i].data.mail);
1835 if (!objs[i].global_mode) {
1836 free(objs[i].data.mail);
1840 case OBJ_if_existing:
1841 case OBJ_if_mounted:
1842 case OBJ_if_running:
1843 free(objs[i].data.ifblock.s);
1844 free(objs[i].data.ifblock.str);
1847 free(objs[i].data.tail.logfile);
1848 free(objs[i].data.tail.buffer);
1850 case OBJ_text: case OBJ_font:
1851 free(objs[i].data.s);
1854 free(objs[i].data.s);
1857 free(objs[i].data.s);
1860 free(objs[i].data.s);
1863 free(objs[i].data.s);
1865 /* case OBJ_execibar:
1866 free(objs[i].data.s);
1868 case OBJ_execigraph:
1869 free(objs[i].data.s);
1872 case OBJ_iconv_start:
1878 if (info.mpd.title) {
1879 free(info.mpd.title);
1883 case OBJ_mpd_artist:
1884 if (info.mpd.artist) {
1885 free(info.mpd.artist);
1886 info.mpd.artist = 0;
1890 if (info.mpd.album) {
1891 free(info.mpd.album);
1895 case OBJ_mpd_random:
1896 if (info.mpd.random) {
1897 free(info.mpd.random);
1898 info.mpd.random = 0;
1901 case OBJ_mpd_repeat:
1902 if (info.mpd.repeat) {
1903 free(info.mpd.repeat);
1904 info.mpd.repeat = 0;
1908 if (info.mpd.track) {
1909 free(info.mpd.track);
1914 if (info.mpd.name) {
1915 free(info.mpd.name);
1920 if (info.mpd.file) {
1921 free(info.mpd.file);
1925 case OBJ_mpd_status:
1926 if (info.mpd.status) {
1927 free(info.mpd.status);
1928 info.mpd.status = 0;
1932 if (info.mpd.artist) {
1933 free(info.mpd.artist);
1934 info.mpd.artist = 0;
1936 if (info.mpd.title) {
1937 free(info.mpd.title);
1940 if (info.mpd.file) {
1941 free(info.mpd.file);
1948 case OBJ_xmms2_artist:
1949 if (info.xmms2.artist) {
1950 free(info.xmms2.artist);
1951 info.xmms2.artist = 0;
1954 case OBJ_xmms2_album:
1955 if (info.xmms2.album) {
1956 free(info.xmms2.album);
1957 info.xmms2.album = 0;
1960 case OBJ_xmms2_title:
1961 if (info.xmms2.title) {
1962 free(info.xmms2.title);
1963 info.xmms2.title = 0;
1966 case OBJ_xmms2_genre:
1967 if (info.xmms2.genre) {
1968 free(info.xmms2.genre);
1969 info.xmms2.genre = 0;
1972 case OBJ_xmms2_comment:
1973 if (info.xmms2.comment) {
1974 free(info.xmms2.comment);
1975 info.xmms2.comment = 0;
1978 case OBJ_xmms2_decoder:
1979 if (info.xmms2.decoder) {
1980 free(info.xmms2.decoder);
1984 case OBJ_xmms2_transport:
1985 if (info.xmms2.transport) {
1986 free(info.xmms2.transport);
1991 if (info.xmms2.url) {
1992 free(info.xmms2.url);
1996 case OBJ_xmms2_date:
1997 if (info.xmms2.date) {
1998 free(info.xmms2.date);
1999 info.xmms2.date = 0;
2002 case OBJ_xmms2_status:
2003 if (info.xmms2.status) {
2004 free(info.xmms2.status);
2005 info.xmms2.status = 0;
2008 case OBJ_xmms2_smart:
2009 if (info.xmms2.artist) {
2010 free(info.xmms2.artist);
2011 info.xmms2.artist = 0;
2013 if (info.xmms2.title) {
2014 free(info.xmms2.title);
2015 info.xmms2.title = 0;
2017 if (info.xmms2.url) {
2018 free(info.xmms2.url);
2024 case OBJ_bmpx_title:
2025 case OBJ_bmpx_artist:
2026 case OBJ_bmpx_album:
2027 case OBJ_bmpx_track:
2029 case OBJ_bmpx_bitrate:
2033 free(objs[i].data.s);
2035 case OBJ_battery_time:
2036 free(objs[i].data.s);
2039 free(objs[i].data.execi.cmd);
2040 free(objs[i].data.execi.buffer);
2043 free(objs[i].data.texeci.cmd);
2044 free(objs[i].data.texeci.buffer);
2047 if (info.first_process) {
2048 free_all_processes();
2049 info.first_process = NULL;
2053 if (info.first_process) {
2054 free_all_processes();
2055 info.first_process = NULL;
2060 free(objs[i].data.hddtemp.dev);
2061 free(objs[i].data.hddtemp.addr);
2064 case OBJ_entropy_avail:
2065 case OBJ_entropy_poolsize:
2066 case OBJ_entropy_bar:
2071 //text_objects = NULL;
2072 //text_object_count = 0;
2075 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2080 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2081 *a = mixer_init(buf1);
2082 (void) scan_bar(arg + n, w, h);
2085 (void) scan_bar(arg, w, h);
2090 /* construct_text_object() creates a new text_object */
2091 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2093 //struct text_object *obj = new_text_object();
2094 struct text_object *obj = new_text_object_internal();
2097 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2098 #define END ; } } else
2102 obj->type = OBJ_color;
2103 obj->data.l = get_x11_color(s);
2106 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2107 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2108 END OBJ(acpiacadapter, 0)
2109 END OBJ(freq, INFO_FREQ)
2115 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2117 obj->data.cpu_index=1;
2118 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2122 obj->data.cpu_index=atoi(&arg[0]);
2125 END OBJ(freq_g, INFO_FREQ)
2131 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2133 obj->data.cpu_index=1;
2134 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2138 obj->data.cpu_index=atoi(&arg[0]);
2141 #if defined(__linux__)
2142 END OBJ(voltage_mv, 0)
2148 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2150 obj->data.cpu_index=1;
2151 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2155 obj->data.cpu_index=atoi(&arg[0]);
2158 END OBJ(voltage_v, 0)
2164 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2166 obj->data.cpu_index=1;
2167 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2171 obj->data.cpu_index=atoi(&arg[0]);
2174 #endif /* __linux__ */
2175 END OBJ(freq_dyn, 0);
2176 END OBJ(freq_dyn_g, 0);
2177 END OBJ(acpifan, 0);
2178 END OBJ(battery, 0);
2181 sscanf(arg, "%63s", bat);
2183 strcpy(bat, "BAT0");
2184 obj->data.s = strdup(bat);
2185 END OBJ(battery_time, 0);
2188 sscanf(arg, "%63s", bat);
2190 strcpy(bat, "BAT0");
2191 obj->data.s = strdup(bat);
2192 END OBJ(battery_percent, 0);
2195 sscanf(arg, "%63s", bat);
2197 strcpy(bat, "BAT0");
2198 obj->data.s = strdup(bat);
2199 END OBJ(battery_bar, 0);
2202 arg = scan_bar(arg, &obj->a, &obj->b);
2203 sscanf(arg, "%63s", bat);
2205 strcpy(bat, "BAT0");
2207 #if defined(__linux__)
2208 END OBJ(i8k_version, INFO_I8K)
2209 END OBJ(i8k_bios, INFO_I8K)
2210 END OBJ(i8k_serial, INFO_I8K)
2211 END OBJ(i8k_cpu_temp, INFO_I8K)
2212 END OBJ(i8k_cpu_tempf, INFO_I8K)
2213 END OBJ(i8k_left_fan_status, INFO_I8K)
2214 END OBJ(i8k_right_fan_status, INFO_I8K)
2215 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2216 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2217 END OBJ(i8k_ac_status, INFO_I8K)
2218 END OBJ(i8k_buttons_status, INFO_I8K)
2220 END OBJ(ibm_temps, 0)
2222 CRIT_ERR("ibm_temps: needs an argument");
2224 if (!isdigit(arg[0])
2226 || atoi(&arg[0]) >=8)
2229 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2231 obj->data.sensor = atoi(&arg[0]);
2232 END OBJ(ibm_volume, 0)
2233 END OBJ(ibm_brightness, 0)
2234 END OBJ(pb_battery, 0)
2235 if (arg && strcmp(arg, "status") == 0) {
2236 obj->data.i = PB_BATT_STATUS;
2237 } else if (arg && strcmp(arg, "percent") == 0) {
2238 obj->data.i = PB_BATT_PERCENT;
2239 } else if (arg && strcmp(arg, "time") == 0) {
2240 obj->data.i = PB_BATT_TIME;
2242 ERR("pb_battery: needs one argument: status, percent or time");
2247 #endif /* __linux__ */
2248 #if defined(__OpenBSD__)
2249 END OBJ(obsd_sensors_temp, 0);
2251 CRIT_ERR("obsd_sensors_temp: needs an argument");
2253 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2255 ERR("Invalid temperature sensor number!");
2257 obj->data.sensor = atoi(&arg[0]);
2258 END OBJ(obsd_sensors_fan, 0);
2260 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2262 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2264 ERR("Invalid fan sensor number!");
2266 obj->data.sensor = atoi(&arg[0]);
2267 END OBJ(obsd_sensors_volt, 0);
2269 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2271 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2273 ERR("Invalid voltage sensor number!");
2275 obj->data.sensor = atoi(&arg[0]);
2276 END OBJ(obsd_vendor, 0);
2277 END OBJ(obsd_product, 0);
2278 #endif /* __OpenBSD__ */
2279 END OBJ(buffers, INFO_BUFFERS)
2280 END OBJ(cached, INFO_BUFFERS)
2281 END OBJ(cpu, INFO_CPU)
2283 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2284 obj->data.cpu_index = atoi(&arg[3]);
2286 } else {obj->data.cpu_index = 0; }
2288 obj->data.cpu_index = 0;
2290 END OBJ(cpubar, INFO_CPU)
2292 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2293 obj->data.cpu_index = atoi(&arg[3]);
2296 else {obj->data.cpu_index = 0;}
2297 (void) scan_bar(arg, &obj->a, &obj->b);
2299 (void) scan_bar(arg, &obj->a, &obj->b);
2300 obj->data.cpu_index = 0;
2302 END OBJ(cpugraph, INFO_CPU)
2304 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2305 obj->data.cpu_index = atoi(&arg[3]);
2308 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2310 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2311 obj->data.cpu_index = 0;
2313 END OBJ(diskio, INFO_DISKIO)
2314 END OBJ(diskio_read, INFO_DISKIO)
2315 END OBJ(diskio_write, INFO_DISKIO)
2316 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2317 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2318 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2321 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2324 obj->data.l = color0;
2326 obj->data.l = color1;
2328 obj->data.l = color2;
2330 obj->data.l = color3;
2332 obj->data.l = color4;
2334 obj->data.l = color5;
2336 obj->data.l = color6;
2338 obj->data.l = color7;
2340 obj->data.l = color8;
2342 obj->data.l = color9;
2344 obj->data.s = scan_font(arg);
2346 OBJ(downspeed, INFO_NET)
2348 obj->data.net = get_net_stat(arg);
2351 CRIT_ERR("downspeed needs argument");
2353 END OBJ(downspeedf, INFO_NET)
2355 obj->data.net = get_net_stat(arg);
2358 CRIT_ERR("downspeedf needs argument");
2360 END OBJ(downspeedgraph, INFO_NET)
2361 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2363 sscanf(arg, "%63s %*i,%*i %*i", buf);
2364 obj->data.net = get_net_stat(buf);
2365 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2366 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2373 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2374 blockstart[blockdepth - 1] = object_count;
2375 obj->data.ifblock.pos = object_count + 2;
2377 ERR("$else: no matching $if_*");
2382 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2384 ERR("$endif: no matching $if_*");
2387 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2390 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2391 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2392 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2393 END OBJ(execibar, 0) unsigned int n;
2394 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2396 ERR("${execibar <interval> command}");
2397 obj->type = OBJ_text;
2398 snprintf(buf, 256, "${%s}", s);
2399 obj->data.s = strdup(buf);
2401 obj->data.execi.cmd = strdup(arg + n);
2403 END OBJ(execigraph, 0) unsigned int n;
2404 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2406 ERR("${execigraph <interval> command}");
2407 obj->type = OBJ_text;
2408 snprintf(buf, 256, "${%s}", s);
2409 obj->data.s = strdup(buf);
2411 obj->data.execi.cmd = strdup(arg + n);
2413 END OBJ(execi, 0) unsigned int n;
2414 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2416 ERR("${execi <interval> command}");
2417 obj->type = OBJ_text;
2418 snprintf(buf, 256, "${%s}", s);
2419 obj->data.s = strdup(buf);
2421 obj->data.execi.cmd = strdup(arg + n);
2422 obj->data.execi.buffer =
2423 (char *) calloc(1, text_buffer_size);
2425 END OBJ(texeci, 0) unsigned int n;
2426 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2428 ERR("${texeci <interval> command}");
2429 obj->type = OBJ_text;
2430 snprintf(buf, 256, "${%s}", s);
2431 obj->data.s = strdup(buf);
2433 obj->data.texeci.cmd = strdup(arg + n);
2434 obj->data.texeci.buffer =
2435 (char *) calloc(1, text_buffer_size);
2437 obj->data.texeci.p_timed_thread = NULL;
2438 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2440 FILE *fp = popen(arg, "r");
2444 n = fread(buf, 1, 2048, fp);
2447 if (n && buf[n - 1] == '\n')
2452 obj->data.s = strdup(buf);
2454 obj->data.s = strdup("");
2457 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2458 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2460 while (isspace(*arg))
2466 obj->data.fsbar.fs = prepare_fs_stat(arg);
2467 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2470 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2474 obj->data.fsbar.fs = prepare_fs_stat(arg);
2475 END OBJ(fs_free, INFO_FS) if (!arg)
2477 obj->data.fs = prepare_fs_stat(arg);
2478 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2480 obj->data.fs = prepare_fs_stat(arg);
2481 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2483 obj->data.fs = prepare_fs_stat(arg);
2484 END OBJ(fs_size, INFO_FS) if (!arg)
2486 obj->data.fs = prepare_fs_stat(arg);
2487 END OBJ(fs_used, INFO_FS) if (!arg)
2489 obj->data.fs = prepare_fs_stat(arg);
2490 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2491 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2492 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2496 ERR("goto needs arguments");
2497 obj->type = OBJ_text;
2498 obj->data.s = strdup("${goto}");
2502 obj->data.i = atoi(arg);
2507 if (sscanf(arg, "%d %d", &a, &b) != 2)
2508 sscanf(arg, "%d", &b);
2512 obj->data.pair.a = a;
2513 obj->data.pair.b = b;
2515 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2519 ERR("i2c needs arguments");
2520 obj->type = OBJ_text;
2521 //obj->data.s = strdup("${i2c}");
2525 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2526 /* if scanf couldn't read three values, read type and num and use
2528 sscanf(arg, "%63s %d", buf2, &n);
2530 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2531 obj->data.i2c.devtype);
2532 strncpy(obj->data.i2c.type, buf2, 63);
2535 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2536 obj->data.i2c.devtype);
2537 strncpy(obj->data.i2c.type, buf2, 63);
2540 END OBJ(top, INFO_TOP)
2544 ERR("top needs arguments");
2545 obj->type = OBJ_text;
2546 //obj->data.s = strdup("${top}");
2549 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2550 if (strcmp(buf, "name") == 0) {
2551 obj->data.top.type = TOP_NAME;
2552 } else if (strcmp(buf, "cpu") == 0) {
2553 obj->data.top.type = TOP_CPU;
2554 } else if (strcmp(buf, "pid") == 0) {
2555 obj->data.top.type = TOP_PID;
2556 } else if (strcmp(buf, "mem") == 0) {
2557 obj->data.top.type = TOP_MEM;
2559 ERR("invalid arg for top");
2562 if (n < 1 || n > 10) {
2563 CRIT_ERR("invalid arg for top");
2566 obj->data.top.num = n - 1;
2570 ERR("invalid args given for top");
2573 END OBJ(top_mem, INFO_TOP)
2577 ERR("top_mem needs arguments");
2578 obj->type = OBJ_text;
2579 obj->data.s = strdup("${top_mem}");
2582 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2583 if (strcmp(buf, "name") == 0) {
2584 obj->data.top.type = TOP_NAME;
2585 } else if (strcmp(buf, "cpu") == 0) {
2586 obj->data.top.type = TOP_CPU;
2587 } else if (strcmp(buf, "pid") == 0) {
2588 obj->data.top.type = TOP_PID;
2589 } else if (strcmp(buf, "mem") == 0) {
2590 obj->data.top.type = TOP_MEM;
2592 ERR("invalid arg for top");
2595 if (n < 1 || n > 10) {
2596 CRIT_ERR("invalid arg for top");
2599 obj->data.top.num = n - 1;
2603 ERR("invalid args given for top");
2606 END OBJ(addr, INFO_NET)
2608 obj->data.net = get_net_stat(arg);
2611 CRIT_ERR("addr needs argument");
2613 END OBJ(linkstatus, INFO_WIFI)
2615 obj->data.net = get_net_stat(arg);
2618 CRIT_ERR("linkstatus needs argument");
2624 ERR("tail needs arguments");
2625 obj->type = OBJ_text;
2626 obj->data.s = strdup("${tail}");
2629 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2630 if (n1 < 1 || n1 > 30) {
2631 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2635 fp = fopen(buf, "r");
2637 obj->data.tail.logfile =
2638 malloc(text_buffer_size);
2639 strcpy(obj->data.tail.logfile, buf);
2640 obj->data.tail.wantedlines = n1;
2641 obj->data.tail.interval =
2642 update_interval * 2;
2646 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2649 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2650 if (n1 < 1 || n1 > 30) {
2652 ("invalid arg for tail, number of lines must be between 1 and 30");
2654 } else if (n2 < 1 || n2 < update_interval) {
2656 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2660 fp = fopen(buf, "r");
2662 obj->data.tail.logfile =
2663 malloc(text_buffer_size);
2664 strcpy(obj->data.tail.logfile, buf);
2665 obj->data.tail.wantedlines = n1;
2666 obj->data.tail.interval = n2;
2670 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2676 ERR("invalid args given for tail");
2679 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2684 ERR("head needs arguments");
2685 obj->type = OBJ_text;
2686 obj->data.s = strdup("${head}");
2689 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2690 if (n1 < 1 || n1 > 30) {
2691 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2695 fp = fopen(buf, "r");
2697 obj->data.tail.logfile =
2698 malloc(text_buffer_size);
2699 strcpy(obj->data.tail.logfile, buf);
2700 obj->data.tail.wantedlines = n1;
2701 obj->data.tail.interval =
2702 update_interval * 2;
2706 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2709 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2710 if (n1 < 1 || n1 > 30) {
2712 ("invalid arg for head, number of lines must be between 1 and 30");
2714 } else if (n2 < 1 || n2 < update_interval) {
2716 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2720 fp = fopen(buf, "r");
2722 obj->data.tail.logfile =
2723 malloc(text_buffer_size);
2724 strcpy(obj->data.tail.logfile, buf);
2725 obj->data.tail.wantedlines = n1;
2726 obj->data.tail.interval = n2;
2730 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2736 ERR("invalid args given for head");
2739 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2740 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2742 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2743 if (r >= 3 && (c < 1 || c > 3))
2745 if (r >= 2 && (b < 1 || b > 3))
2747 if (r >= 1 && (a < 1 || a > 3))
2750 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2751 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2752 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2753 END OBJ(if_empty, 0)
2754 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2755 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2758 ERR("if_empty needs an argument");
2759 obj->data.ifblock.s = 0;
2761 obj->data.ifblock.s = strdup(arg);
2762 blockstart[blockdepth] = object_count;
2763 obj->data.ifblock.pos = object_count + 2;
2765 END OBJ(if_existing, 0)
2766 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2767 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2770 ERR("if_existing needs an argument or two");
2771 obj->data.ifblock.s = NULL;
2772 obj->data.ifblock.str = NULL;
2774 char buf1[256], buf2[256];
2775 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2777 obj->data.ifblock.s = strdup(buf1);
2778 obj->data.ifblock.str = NULL;
2780 obj->data.ifblock.s = strdup(buf1);
2781 obj->data.ifblock.str = strdup(buf2);
2784 blockstart[blockdepth] = object_count;
2785 obj->data.ifblock.pos = object_count + 2;
2787 END OBJ(if_mounted, 0)
2788 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2789 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2792 ERR("if_mounted needs an argument");
2793 obj->data.ifblock.s = 0;
2795 obj->data.ifblock.s = strdup(arg);
2796 blockstart[blockdepth] = object_count;
2797 obj->data.ifblock.pos = object_count + 2;
2799 END OBJ(if_running, 0)
2800 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2801 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2805 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2806 obj->data.ifblock.s = strdup(buf);
2808 ERR("if_running needs an argument");
2809 obj->data.ifblock.s = 0;
2811 blockstart[blockdepth] = object_count;
2812 obj->data.ifblock.pos = object_count + 2;
2816 END OBJ(mails, INFO_MAIL)
2817 END OBJ(mboxscan, 0)
2818 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2819 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2820 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2821 obj->data.mboxscan.output[0] = 1;
2822 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2823 END OBJ(mem, INFO_MEM)
2824 END OBJ(memmax, INFO_MEM)
2825 END OBJ(memperc, INFO_MEM)
2826 END OBJ(membar, INFO_MEM)
2827 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2828 END OBJ(memgraph, INFO_MEM)
2829 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2830 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2831 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2832 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2833 END OBJ(mixerbar, INFO_MIXER)
2834 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2835 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2836 END OBJ(mixerlbar, INFO_MIXER)
2837 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2838 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2839 END OBJ(mixerrbar, INFO_MIXER)
2840 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2841 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2843 OBJ(new_mails, INFO_MAIL)
2844 END OBJ(nodename, 0)
2845 END OBJ(processes, INFO_PROCS)
2846 END OBJ(running_processes, INFO_RUN_PROCS)
2847 END OBJ(shadecolor, 0)
2849 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2851 END OBJ(outlinecolor, 0)
2853 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2855 END OBJ(stippled_hr, 0)
2857 int a = stippled_borders, b = 1;
2859 if (sscanf(arg, "%d %d", &a, &b) != 2)
2860 sscanf(arg, "%d", &b);
2864 obj->data.pair.a = a;
2865 obj->data.pair.b = b;
2867 END OBJ(swap, INFO_MEM)
2868 END OBJ(swapmax, INFO_MEM)
2869 END OBJ(swapperc, INFO_MEM)
2870 END OBJ(swapbar, INFO_MEM)
2871 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2872 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2874 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2875 obj->data.i2c.devtype);
2876 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2878 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2879 obj->data.i2c.devtype);
2880 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2881 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2883 char buf1[256], buf2[256], *fmt, *tz;
2886 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2895 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2896 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2898 END OBJ(iconv_start, 0)
2899 if (iconv_converting) {
2900 CRIT_ERR("You must stop your last iconv conversion before starting another");
2903 char iconv_from[CODEPAGE_LENGTH];
2904 char iconv_to[CODEPAGE_LENGTH];
2905 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2906 CRIT_ERR("Invalid arguments for iconv_start");
2909 new_iconv = iconv_open(iconv_to, iconv_from);
2910 if (new_iconv == (iconv_t)(-1)) {
2911 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2913 obj->a = register_iconv(&new_iconv);
2914 iconv_converting = 1;
2918 CRIT_ERR("Iconv requires arguments");
2920 END OBJ(iconv_stop, 0)
2921 iconv_converting = 0;
2924 END OBJ(totaldown, INFO_NET)
2926 obj->data.net = get_net_stat(arg);
2929 CRIT_ERR("totaldown needs argument");
2931 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2933 obj->data.net = get_net_stat(arg);
2936 CRIT_ERR("totalup needs argument");
2939 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2940 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2941 END OBJ(upspeed, INFO_NET)
2943 obj->data.net = get_net_stat(arg);
2946 CRIT_ERR("upspeed needs argument");
2948 END OBJ(upspeedf, INFO_NET)
2950 obj->data.net = get_net_stat(arg);
2953 CRIT_ERR("upspeedf needs argument");
2956 END OBJ(upspeedgraph, INFO_NET)
2957 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2959 sscanf(arg, "%63s %*i,%*i %*i", buf);
2960 obj->data.net = get_net_stat(buf);
2961 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2962 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2967 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2968 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2969 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2970 OBJ(apm_adapter, 0) END
2971 OBJ(apm_battery_life, 0) END
2972 OBJ(apm_battery_time, 0) END
2973 #endif /* __FreeBSD__ */
2977 obj->data.mail = parse_mail_args(IMAP, arg);
2978 obj->global_mode = 0;
2980 obj->global_mode = 1;
2983 OBJ(imap_messages, 0)
2986 obj->data.mail = parse_mail_args(IMAP, arg);
2987 obj->global_mode = 0;
2989 obj->global_mode = 1;
2995 obj->data.mail = parse_mail_args(POP3, arg);
2996 obj->global_mode = 0;
2998 obj->global_mode = 1;
3004 obj->data.mail = parse_mail_args(POP3, arg);
3005 obj->global_mode = 0;
3007 obj->global_mode = 1;
3011 OBJ(mpd_artist, INFO_MPD)
3012 END OBJ(mpd_title, INFO_MPD)
3013 END OBJ(mpd_random, INFO_MPD)
3014 END OBJ(mpd_repeat, INFO_MPD)
3015 END OBJ(mpd_elapsed, INFO_MPD)
3016 END OBJ(mpd_length, INFO_MPD)
3017 END OBJ(mpd_track, INFO_MPD)
3018 END OBJ(mpd_name, INFO_MPD)
3019 END OBJ(mpd_file, INFO_MPD)
3020 END OBJ(mpd_percent, INFO_MPD)
3021 END OBJ(mpd_album, INFO_MPD)
3022 END OBJ(mpd_vol, INFO_MPD)
3023 END OBJ(mpd_bitrate, INFO_MPD)
3024 END OBJ(mpd_status, INFO_MPD)
3025 END OBJ(mpd_bar, INFO_MPD)
3026 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3027 END OBJ(mpd_smart, INFO_MPD) END
3030 OBJ(xmms2_artist, INFO_XMMS2)
3031 END OBJ(xmms2_album, INFO_XMMS2)
3032 END OBJ(xmms2_title, INFO_XMMS2)
3033 END OBJ(xmms2_genre, INFO_XMMS2)
3034 END OBJ(xmms2_comment, INFO_XMMS2)
3035 END OBJ(xmms2_decoder, INFO_XMMS2)
3036 END OBJ(xmms2_transport, INFO_XMMS2)
3037 END OBJ(xmms2_url, INFO_XMMS2)
3038 END OBJ(xmms2_tracknr, INFO_XMMS2)
3039 END OBJ(xmms2_bitrate, INFO_XMMS2)
3040 END OBJ(xmms2_date, INFO_XMMS2)
3041 END OBJ(xmms2_id, INFO_XMMS2)
3042 END OBJ(xmms2_duration, INFO_XMMS2)
3043 END OBJ(xmms2_elapsed, INFO_XMMS2)
3044 END OBJ(xmms2_size, INFO_XMMS2)
3045 END OBJ(xmms2_status, INFO_XMMS2)
3046 END OBJ(xmms2_percent, INFO_XMMS2)
3047 END OBJ(xmms2_bar, INFO_XMMS2)
3048 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3049 END OBJ(xmms2_smart, INFO_XMMS2)
3053 OBJ(audacious_status, INFO_AUDACIOUS) END
3054 OBJ(audacious_title, INFO_AUDACIOUS)
3058 sscanf (arg, "%d", &info.audacious.max_title_len);
3059 if (info.audacious.max_title_len > 0)
3060 info.audacious.max_title_len++;
3062 CRIT_ERR ("audacious_title: invalid length argument");
3066 OBJ(audacious_length, INFO_AUDACIOUS) END
3067 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3068 OBJ(audacious_position, INFO_AUDACIOUS) END
3069 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3070 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3071 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3072 OBJ(audacious_channels, INFO_AUDACIOUS) END
3073 OBJ(audacious_filename, INFO_AUDACIOUS) END
3074 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3075 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3076 OBJ(audacious_bar, INFO_AUDACIOUS)
3077 (void) scan_bar(arg, &obj->a, &obj->b);
3081 OBJ(bmpx_title, INFO_BMPX)
3082 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3084 OBJ(bmpx_artist, INFO_BMPX)
3085 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3087 OBJ(bmpx_album, INFO_BMPX)
3088 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3090 OBJ(bmpx_track, INFO_BMPX)
3091 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3093 OBJ(bmpx_uri, INFO_BMPX)
3094 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3096 OBJ(bmpx_bitrate, INFO_BMPX)
3097 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3102 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3103 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3104 ERR("hddtemp needs arguments");
3105 obj->type = OBJ_text;
3106 obj->data.s = strdup("${hddtemp}");
3111 #ifdef TCP_PORT_MONITOR
3112 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3113 int argc, port_begin, port_end, item, connection_index;
3115 memset(itembuf,0,sizeof(itembuf));
3117 /* massive argument checking */
3119 CRIT_ERR("tcp_portmon: needs arguments");
3121 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3122 if ( (argc != 3) && (argc != 4) )
3124 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3126 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3128 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3130 if ( port_begin > port_end )
3132 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3134 if ( strncmp(itembuf,"count",31) == 0 )
3136 else if ( strncmp(itembuf,"rip",31) == 0 )
3138 else if ( strncmp(itembuf,"rhost",31) == 0 )
3140 else if ( strncmp(itembuf,"rport",31) == 0 )
3142 else if ( strncmp(itembuf,"rservice",31) == 0 )
3144 else if ( strncmp(itembuf,"lip",31) == 0 )
3146 else if ( strncmp(itembuf,"lhost",31) == 0 )
3148 else if ( strncmp(itembuf,"lport",31) == 0 )
3150 else if ( strncmp(itembuf,"lservice",31) == 0 )
3154 CRIT_ERR("tcp_portmon: invalid item specified");
3156 if ( (argc==3) && (item!=COUNT) )
3158 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3160 if ( (argc==4) && (connection_index<0) )
3162 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3164 /* ok, args looks good. save the text object data */
3165 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3166 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3167 obj->data.tcp_port_monitor.item = item;
3168 obj->data.tcp_port_monitor.connection_index = connection_index;
3170 /* if the port monitor collection hasn't been created, we must create it */
3171 if ( !info.p_tcp_port_monitor_collection )
3173 info.p_tcp_port_monitor_collection =
3174 create_tcp_port_monitor_collection ();
3175 if ( !info.p_tcp_port_monitor_collection )
3177 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3181 /* if a port monitor for this port does not exist, create one and add it to the collection */
3182 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3184 tcp_port_monitor_t * p_monitor =
3185 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3188 CRIT_ERR("tcp_portmon: unable to create port monitor");
3190 /* add the newly created monitor to the collection */
3191 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3194 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3199 OBJ(entropy_avail, INFO_ENTROPY) END
3200 OBJ(entropy_poolsize, INFO_ENTROPY) END
3201 OBJ(entropy_bar, INFO_ENTROPY)
3202 (void) scan_bar(arg, &obj->a, &obj->b);
3207 ERR("unknown variable %s", s);
3208 obj->type = OBJ_text;
3209 snprintf(buf, 256, "${%s}", s);
3210 obj->data.s = strdup(buf);
3217 static struct text_object *create_plain_text(const char *s)
3219 struct text_object *obj;
3221 if (s == NULL || *s == '\0') {
3225 obj = new_text_object_internal();
3227 obj->type = OBJ_text;
3228 obj->data.s = strdup(s);
3232 static struct text_object_list *extract_variable_text_internal(const char *p)
3234 struct text_object_list *retval;
3235 struct text_object *obj;
3238 retval = malloc(sizeof(struct text_object_list));
3239 memset(retval, 0, sizeof(struct text_object_list));
3240 retval->text_object_count = 0;
3242 long line = text_lines;
3250 obj = create_plain_text(s);
3252 // allocate memory for the object
3253 retval->text_objects = realloc(retval->text_objects,
3254 sizeof(struct text_object) * (retval->text_object_count+1));
3255 // assign the new object to the end of the list.
3256 memcpy(&retval->text_objects[retval->text_object_count++],
3257 obj, sizeof(struct text_object));
3269 /* variable is either $foo or ${foo} */
3271 unsigned int brl = 1, brr = 0;
3274 while (*p && brl != brr) {
3275 if (*p == '{') brl++;
3276 if (*p == '}') brr++;
3284 while (*p && (isalnum((int) *p)
3289 /* copy variable to buffer */
3290 len = (p - s > 255) ? 255 : (p - s);
3291 strncpy(buf, s, len);
3300 /* if variable wasn't found from environment, use some special */
3306 if (strchr(buf, ' ')) {
3307 arg = strchr(buf, ' ');
3310 while (isspace((int) *arg))
3316 /* lowercase variable name */
3323 // create new object
3324 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3326 // allocate memory for the object
3327 retval->text_objects = realloc(retval->text_objects,
3328 sizeof(struct text_object) * (retval->text_object_count+1));
3329 // assign the new object to the end of the list.
3330 memcpy(&retval->text_objects[retval->text_object_count++],
3331 obj, sizeof(struct text_object));
3337 obj = create_plain_text("$");
3339 // allocate memory for the object
3340 retval->text_objects = realloc(retval->text_objects,
3341 sizeof(struct text_object) * (retval->text_object_count+1));
3342 // assign the new object to the end of the list.
3343 memcpy(&retval->text_objects[retval->text_object_count++],
3344 obj, sizeof(struct text_object));
3351 obj = create_plain_text(s);
3353 // allocate memory for the object
3354 retval->text_objects = realloc(retval->text_objects,
3355 sizeof(struct text_object) * (retval->text_object_count+1));
3356 // assign the new object to the end of the list.
3357 memcpy(&retval->text_objects[retval->text_object_count++],
3358 obj, sizeof(struct text_object));
3363 ERR("one or more $endif's are missing");
3369 static void extract_variable_text(const char *p)
3371 struct text_object_list *list;
3373 free_text_objects(text_object_count, text_objects);
3374 text_object_count = 0;
3375 text_objects = NULL;
3378 list = extract_variable_text_internal(p);
3379 text_objects = list->text_objects;
3380 text_object_count = list->text_object_count;
3387 void parse_conky_vars(char * text, char * p, struct information *cur) {
3388 struct text_object_list *object_list = extract_variable_text_internal(text);
3389 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3393 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3398 char buff_in[P_MAX_SIZE] = {0};
3399 iconv_converting = 0;
3402 for (i = 0; i < object_count; i++) {
3403 struct text_object *obj = &objs[i];
3405 #define OBJ(a) break; case OBJ_##a:
3407 switch (obj->type) {
3410 ERR("not implemented obj type %d",
3414 /* does anyone have decimals in acpi temperature? */
3416 snprintf(p, p_max_size, "%d", (int)
3417 get_acpi_temperature(obj->
3421 snprintf(p, 5, "%d ", (int)
3422 get_acpi_temperature(obj->
3427 /* does anyone have decimals in acpi temperature? */
3429 snprintf(p, p_max_size, "%d", (int)
3430 ((get_acpi_temperature(obj->
3432 i)+ 40) * 9.0 / 5 - 40));
3434 snprintf(p, 5, "%d ", (int)
3435 ((get_acpi_temperature(obj->
3437 i)+ 40) * 9.0 / 5 - 40));
3441 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3446 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3449 #if defined(__linux__)
3452 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3457 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3460 #endif /* __linux__ */
3464 get_freq_dynamic(p, 6, "%.0f ", 1 );
3466 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3471 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3473 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3477 get_adt746x_cpu(p, p_max_size);
3480 get_adt746x_fan(p, p_max_size);
3483 get_acpi_fan(p, p_max_size);
3485 OBJ(acpiacadapter) {
3486 get_acpi_ac_adapter(p, p_max_size);
3489 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3492 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3494 OBJ(battery_percent) {
3495 snprintf(p, p_max_size, "%d",
3496 get_battery_perct(obj->data.s));
3499 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3502 human_readable(cur->buffers * 1024, p, 255);
3505 human_readable(cur->cached * 1024, p, 255);
3508 if (obj->data.cpu_index > info.cpu_count) {
3509 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3510 CRIT_ERR("attempting to use more CPUs then you have!");
3513 snprintf(p, p_max_size, "%*d", pad_percents,
3514 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3517 snprintf(p, 4, "%*d ",
3519 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3525 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3528 new_graph(p, obj->a,
3529 obj->b, obj->c, obj->d,
3530 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3534 new_fg(p, obj->data.l);
3566 #if defined(__linux__)
3568 snprintf(p, p_max_size, "%s", i8k.version);
3571 snprintf(p, p_max_size, "%s", i8k.bios);
3574 snprintf(p, p_max_size, "%s", i8k.serial);
3577 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3579 OBJ(i8k_cpu_tempf) {
3581 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3582 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3584 OBJ(i8k_left_fan_status) {
3585 int left_fan_status;
3586 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3587 if(left_fan_status == 0) {
3588 snprintf(p, p_max_size,"off");
3589 } if(left_fan_status == 1) {
3590 snprintf(p, p_max_size, "low");
3591 } if(left_fan_status == 2) {
3592 snprintf(p, p_max_size, "high");
3596 OBJ(i8k_right_fan_status) {
3597 int right_fan_status;
3598 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3599 if(right_fan_status == 0) {
3600 snprintf(p, p_max_size,"off");
3601 } if(right_fan_status == 1) {
3602 snprintf(p, p_max_size, "low");
3603 } if(right_fan_status == 2) {
3604 snprintf(p, p_max_size, "high");
3607 OBJ(i8k_left_fan_rpm) {
3608 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3610 OBJ(i8k_right_fan_rpm) {
3611 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3613 OBJ(i8k_ac_status) {
3615 sscanf(i8k.ac_status, "%d", &ac_status);
3616 if(ac_status == -1) {
3617 snprintf(p, p_max_size,"disabled (read i8k docs)");
3618 } if(ac_status == 0) {
3619 snprintf(p, p_max_size, "off");
3620 } if(ac_status == 1) {
3621 snprintf(p, p_max_size, "on");
3624 OBJ(i8k_buttons_status) {
3625 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3629 get_ibm_acpi_fan(p, p_max_size);
3632 get_ibm_acpi_temps();
3633 snprintf(p, p_max_size, "%d",
3634 ibm_acpi.temps[obj->data.sensor]);
3637 get_ibm_acpi_volume(p, p_max_size);
3639 OBJ(ibm_brightness) {
3640 get_ibm_acpi_brightness(p, p_max_size);
3643 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3645 #endif /* __linux__ */
3648 OBJ(obsd_sensors_temp) {
3649 obsd_sensors.device = sensor_device;
3650 update_obsd_sensors();
3651 snprintf(p, p_max_size, "%.1f",
3652 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3655 OBJ(obsd_sensors_fan) {
3656 obsd_sensors.device = sensor_device;
3657 update_obsd_sensors();
3658 snprintf(p, p_max_size, "%d",
3659 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3662 OBJ(obsd_sensors_volt) {
3663 obsd_sensors.device = sensor_device;
3664 update_obsd_sensors();
3665 snprintf(p, p_max_size, "%.2f",
3666 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3670 get_obsd_vendor(p, p_max_size);
3674 get_obsd_product(p, p_max_size);
3676 #endif /* __OpenBSD__ */
3680 new_font(p, obj->data.s);
3683 void format_diskio(unsigned int diskio_value)
3686 if (diskio_value > 1024*1024) {
3687 snprintf(p, p_max_size, "%.1fGiB",
3688 (double)diskio_value/1024/1024);
3689 } else if (diskio_value > 1024) {
3690 snprintf(p, p_max_size, "%.1fMiB",
3691 (double)diskio_value/1024);
3692 } else if (diskio_value > 0) {
3693 snprintf(p, p_max_size, "%dKiB", diskio_value);
3695 snprintf(p, p_max_size, "%dB", diskio_value);
3698 if (diskio_value > 1024*1024) {
3699 snprintf(p, 12, "%.1fGiB ",
3700 (double)diskio_value/1024/1024);
3701 } else if (diskio_value > 1024) {
3702 snprintf(p, 12, "%.1fMiB ",
3703 (double)diskio_value/1024);
3704 } else if (diskio_value > 0) {
3705 snprintf(p, 12, "%dKiB ", diskio_value);
3707 snprintf(p, 12, "%dB ", diskio_value);
3712 format_diskio(diskio_value);
3715 format_diskio(diskio_write_value);
3718 format_diskio(diskio_read_value);
3721 new_graph(p, obj->a,
3722 obj->b, obj->c, obj->d,
3723 diskio_value, obj->e, 1);
3725 OBJ(diskiograph_read) {
3726 new_graph(p, obj->a,
3727 obj->b, obj->c, obj->d,
3728 diskio_read_value, obj->e, 1);
3730 OBJ(diskiograph_write) {
3731 new_graph(p, obj->a,
3732 obj->b, obj->c, obj->d,
3733 diskio_write_value, obj->e, 1);
3737 snprintf(p, p_max_size, "%d",
3738 (int) (obj->data.net->
3742 snprintf(p, 6, "%d ",
3743 (int) (obj->data.net->
3749 snprintf(p, p_max_size, "%.1f",
3751 recv_speed / 1024.0);
3753 snprintf(p, 8, "%.1f ",
3755 recv_speed / 1024.0);
3757 OBJ(downspeedgraph) {
3759 if (obj->data.net->recv_speed == 0)
3760 obj->data.net->recv_speed = 0.01;
3762 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3763 (obj->data.net->recv_speed /
3764 1024.0), obj->e, 1);
3768 i = obj->data.ifblock.pos - 1;
3778 snprintf(p, p_max_size, "%u.%u.%u.%u",
3779 obj->data.net->addr.
3781 obj->data.net->addr.
3783 obj->data.net->addr.
3785 obj->data.net->addr.
3791 snprintf(p, p_max_size, "%d",
3792 obj->data.net->linkstatus);
3795 snprintf(p, 5, "%4d ",
3796 obj->data.net->linkstatus);
3799 #if defined(IMLIB2) && defined(X11)
3804 Imlib_Image image, buffer;
3805 image = imlib_load_image(obj->data.s);
3806 imlib_context_set_image(image);
3809 w = imlib_image_get_width();
3810 h = imlib_image_get_height();
3811 buffer = imlib_create_image(w, h);
3812 imlib_context_set_display(display);
3813 imlib_context_set_drawable(window.drawable);
3814 imlib_context_set_colormap(DefaultColormap(display, screen));
3815 imlib_context_set_visual(DefaultVisual(display, screen));
3816 imlib_context_set_image(buffer);
3817 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3818 imlib_render_image_on_drawable(text_start_x, text_start_y);
3820 imlib_context_set_image(image);
3827 FILE *fp = popen(obj->data.s, "r");
3828 int length = fread(p, 1, p_max_size, fp);
3831 /*output[length] = '\0';
3832 if (length > 0 && output[length - 1] == '\n') {
3833 output[length - 1] = '\0';
3836 if (length > 0 && p[length - 1] == '\n') {
3837 p[length - 1] = '\0';
3840 //parse_conky_vars(output, p, cur);
3844 FILE *fp = popen(obj->data.s, "r");
3845 int n2 = fread(p, 1, p_max_size, fp);
3849 if (n2 && p[n2 - 1] == '\n')
3858 if (sscanf(p, "%lf", &barnum) == 0) {
3859 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3861 if (barnum > 100 || barnum < 0) {
3862 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3864 barnum = barnum / 100.0;
3865 new_bar(p, 0, 4, (int) (barnum * 255.0));
3871 FILE *fp = popen(obj->data.s, "r");
3872 int n2 = fread(p, 1, p_max_size, fp);
3876 if (n2 && p[n2 - 1] == '\n')
3885 if (sscanf(p, "%lf", &barnum) == 0) {
3886 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3888 if (barnum > 100 || barnum < 0) {
3889 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3891 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3896 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3897 new_bar(p, 0, 4, (int) obj->f);
3900 FILE *fp = popen(obj->data.execi.cmd, "r");
3901 int n2 = fread(p, 1, p_max_size, fp);
3904 if (n2 && p[n2 - 1] == '\n')
3913 if (sscanf(p, "%f", &barnum) == 0) {
3914 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3916 if (barnum > 100 || barnum < 0) {
3917 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3919 obj->f = 255 * barnum / 100.0;
3920 new_bar(p, 0, 4, (int) obj->f);
3922 obj->data.execi.last_update =
3923 current_update_time;
3927 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3928 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3931 FILE *fp = popen(obj->data.execi.cmd, "r");
3932 int n2 = fread(p, 1, p_max_size, fp);
3935 if (n2 && p[n2 - 1] == '\n')
3944 if (sscanf(p, "%f", &barnum) == 0) {
3945 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3947 if (barnum > 100 || barnum < 0) {
3948 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3951 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3953 obj->data.execi.last_update = current_update_time;
3959 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3960 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3962 char *output = obj->data.execi.buffer;
3963 FILE *fp = popen(obj->data.execi.cmd, "r");
3964 //int length = fread(output, 1, text_buffer_size, fp);
3965 int length = fread(output, 1, text_buffer_size, fp);
3968 output[length] = '\0';
3969 if (length > 0 && output[length - 1] == '\n') {
3970 output[length - 1] = '\0';
3972 obj->data.execi.last_update = current_update_time;
3973 snprintf(p, p_max_size, "%s", output);
3975 //parse_conky_vars(output, p, cur);
3978 if (!obj->data.texeci.p_timed_thread)
3980 obj->data.texeci.p_timed_thread=
3981 timed_thread_create ((void*)threaded_exec, (void*) obj,
3982 obj->data.texeci.interval * 1000000);
3983 if (!obj->data.texeci.p_timed_thread)
3984 ERR("Error starting texeci thread");
3985 timed_thread_register (obj->data.texeci.p_timed_thread,
3986 &obj->data.texeci.p_timed_thread);
3988 timed_thread_lock (obj->data.texeci.p_timed_thread);
3989 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
3990 timed_thread_unlock (obj->data.texeci.p_timed_thread);
3992 #endif /* HAVE_POPEN */
3994 if (obj->global_mode && info.mail) { // this means we use info
3995 if (!info.mail->p_timed_thread)
3997 info.mail->p_timed_thread =
3998 timed_thread_create ((void*)imap_thread,
4000 info.mail->interval * 1000000);
4001 if (!info.mail->p_timed_thread)
4002 ERR("Error starting imap thread");
4003 timed_thread_register (info.mail->p_timed_thread,
4004 &info.mail->p_timed_thread);
4006 timed_thread_lock (info.mail->p_timed_thread);
4007 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4008 timed_thread_unlock (info.mail->p_timed_thread);
4009 } else if (obj->data.mail) { // this means we use obj
4010 if (!obj->data.mail->p_timed_thread)
4012 obj->data.mail->p_timed_thread =
4013 timed_thread_create ((void*)imap_thread,
4014 (void*)obj->data.mail,
4015 obj->data.mail->interval * 1000000);
4016 if (!obj->data.mail->p_timed_thread)
4017 ERR("Error starting imap thread");
4018 timed_thread_register (obj->data.mail->p_timed_thread,
4019 &obj->data.mail->p_timed_thread);
4021 timed_thread_lock (obj->data.mail->p_timed_thread);
4022 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4023 timed_thread_unlock (obj->data.mail->p_timed_thread);
4024 } else if (!obj->a) { // something is wrong, warn once then stop
4025 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4029 OBJ(imap_messages) {
4030 if (obj->global_mode && info.mail) { // this means we use info
4031 if (!info.mail->p_timed_thread)
4033 info.mail->p_timed_thread =
4034 timed_thread_create ((void*)imap_thread,
4036 info.mail->interval * 1000000);
4037 if (!info.mail->p_timed_thread)
4038 ERR("Error starting imap thread");
4039 timed_thread_register (info.mail->p_timed_thread,
4040 &info.mail->p_timed_thread);
4042 timed_thread_lock (info.mail->p_timed_thread);
4043 snprintf(p, p_max_size, "%lu", info.mail->messages);
4044 timed_thread_unlock (info.mail->p_timed_thread);
4045 } else if (obj->data.mail) { // this means we use obj
4046 if (!obj->data.mail->p_timed_thread)
4048 obj->data.mail->p_timed_thread =
4049 timed_thread_create ((void*)imap_thread,
4050 (void*)obj->data.mail,
4051 obj->data.mail->interval * 1000000);
4052 if (!obj->data.mail->p_timed_thread)
4053 ERR("Error starting imap thread");
4054 timed_thread_register (obj->data.mail->p_timed_thread,
4055 &obj->data.mail->p_timed_thread);
4057 timed_thread_lock (obj->data.mail->p_timed_thread);
4058 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4059 timed_thread_lock (obj->data.mail->p_timed_thread);
4060 } else if (!obj->a) { // something is wrong, warn once then stop
4061 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4066 if (obj->global_mode && info.mail) { // this means we use info
4067 if (!info.mail->p_timed_thread)
4069 info.mail->p_timed_thread =
4070 timed_thread_create ((void*)pop3_thread,
4072 info.mail->interval * 1000000);
4073 if (!info.mail->p_timed_thread)
4074 ERR("Error starting pop3 thread");
4075 timed_thread_register (info.mail->p_timed_thread,
4076 &info.mail->p_timed_thread);
4078 timed_thread_lock (info.mail->p_timed_thread);
4079 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4080 timed_thread_unlock (info.mail->p_timed_thread);
4081 } else if (obj->data.mail) { // this means we use obj
4082 if (!obj->data.mail->p_timed_thread)
4084 obj->data.mail->p_timed_thread =
4085 timed_thread_create ((void*)pop3_thread,
4086 (void*)obj->data.mail,
4087 obj->data.mail->interval * 1000000);
4088 if (!obj->data.mail->p_timed_thread)
4089 ERR("Error starting pop3 thread");
4090 timed_thread_register (obj->data.mail->p_timed_thread,
4091 &obj->data.mail->p_timed_thread);
4093 timed_thread_lock (obj->data.mail->p_timed_thread);
4094 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4095 timed_thread_unlock (obj->data.mail->p_timed_thread);
4096 } else if (!obj->a) { // something is wrong, warn once then stop
4097 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4102 if (obj->global_mode && info.mail) { // this means we use info
4103 if (!info.mail->p_timed_thread)
4105 info.mail->p_timed_thread =
4106 timed_thread_create ((void*)pop3_thread,
4108 info.mail->interval * 1000000);
4109 if (!info.mail->p_timed_thread)
4110 ERR("Error starting pop3 thread");
4111 timed_thread_register (info.mail->p_timed_thread,
4112 &info.mail->p_timed_thread);
4114 timed_thread_lock (info.mail->p_timed_thread);
4115 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4116 timed_thread_unlock (info.mail->p_timed_thread);
4117 } else if (obj->data.mail) { // this means we use obj
4118 if (!obj->data.mail->p_timed_thread)
4120 obj->data.mail->p_timed_thread =
4121 timed_thread_create ((void*)pop3_thread,
4122 (void*)obj->data.mail,
4123 obj->data.mail->interval * 1000000);
4124 if (!obj->data.mail->p_timed_thread)
4125 ERR("Error starting pop3 thread");
4126 timed_thread_register (obj->data.mail->p_timed_thread,
4127 &obj->data.mail->p_timed_thread);
4129 timed_thread_lock (obj->data.mail->p_timed_thread);
4130 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4131 timed_thread_unlock (obj->data.mail->p_timed_thread);
4132 } else if (!obj->a) { // something is wrong, warn once then stop
4133 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4138 if (obj->data.fs != NULL) {
4139 if (obj->data.fs->size == 0)
4158 if (obj->data.fs != NULL)
4159 human_readable(obj->data.fs->avail,
4163 if (obj->data.fs != NULL) {
4164 if (obj->data.fs->size)
4165 snprintf(p, p_max_size, "%*d",
4174 snprintf(p, p_max_size, "0");
4178 if (obj->data.fs != NULL)
4179 human_readable(obj->data.fs->size,
4183 if (obj->data.fs != NULL)
4184 human_readable(obj->data.fs->size -
4185 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4189 if (obj->data.fs != NULL) {
4190 if (obj->data.fs->size == 0)
4208 if (obj->data.fs != NULL) {
4209 if (obj->data.fs->size)
4210 snprintf(p, 4, "%d",
4220 snprintf(p, p_max_size, "0");
4224 float *v = info.loadavg;
4226 if (obj->data.loadavg[2])
4227 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4228 v[obj->data.loadavg[0] -
4230 v[obj->data.loadavg[1] -
4232 v[obj->data.loadavg[2] -
4234 else if (obj->data.loadavg[1])
4235 snprintf(p, p_max_size, "%.2f %.2f",
4236 v[obj->data.loadavg[0] -
4238 v[obj->data.loadavg[1] -
4240 else if (obj->data.loadavg[0])
4241 snprintf(p, p_max_size, "%.2f",
4242 v[obj->data.loadavg[0] -
4246 new_goto(p, obj->data.i);
4249 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4252 new_hr(p, obj->data.i);
4259 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4260 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4262 snprintf(p, p_max_size, "N/A");
4263 } else if (unit == '*') {
4264 snprintf(p, p_max_size, "%s", temp);
4266 snprintf(p, p_max_size, "%s°%c", temp, unit);
4271 new_offset(p, obj->data.i);
4274 new_voffset(p, obj->data.i);
4279 r = get_i2c_info(&obj->data.i2c.fd,
4281 obj->data.i2c.devtype,
4282 obj->data.i2c.type);
4284 if (r >= 100.0 || r == 0)
4285 snprintf(p, p_max_size, "%d", (int) r);
4287 snprintf(p, p_max_size, "%.1f", r);
4290 new_alignr(p, obj->data.i);
4293 new_alignc(p, obj->data.i);
4296 struct information *my_info =
4297 malloc(sizeof(struct information));
4298 memcpy(my_info, cur, sizeof(struct information));
4299 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4300 if (strlen(p) != 0) {
4301 i = obj->data.ifblock.pos;
4311 if ((obj->data.ifblock.s)
4312 && (stat(obj->data.ifblock.s, &tmp) ==
4314 i = obj->data.ifblock.pos;
4317 if (obj->data.ifblock.str) {
4318 if (!check_contains(obj->data.ifblock.s,
4319 obj->data.ifblock.str)) {
4320 i = obj->data.ifblock.pos;
4329 if ((obj->data.ifblock.s)
4330 && (!check_mount(obj->data.ifblock.s))) {
4331 i = obj->data.ifblock.pos;
4338 if ((obj->data.ifblock.s)
4339 && system(obj->data.ifblock.s)) {
4340 i = obj->data.ifblock.pos;
4347 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4350 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4355 human_readable(cur->mem * 1024, p, 255);
4358 human_readable(cur->memmax * 1024, p, 255);
4363 snprintf(p, p_max_size, "%*Lu",
4368 snprintf(p, 4, "%*Lu ",
4375 new_bar(p, obj->data.pair.a,
4377 cur->memmax ? (cur->mem * 255) /
4382 new_graph(p, obj->a,
4383 obj->b, obj->c, obj->d,
4384 cur->memmax ? (cur->mem * 100.0) /
4385 (cur->memmax) : 0.0, 100, 1);
4389 snprintf(p, p_max_size, "%d",
4390 mixer_get_avg(obj->data.l));
4393 snprintf(p, p_max_size, "%d",
4394 mixer_get_left(obj->data.l));
4397 snprintf(p, p_max_size, "%d",
4398 mixer_get_right(obj->data.l));
4401 new_bar(p, obj->data.mixerbar.w,
4402 obj->data.mixerbar.h,
4403 mixer_get_avg(obj->data.mixerbar.
4407 new_bar(p, obj->data.mixerbar.w,
4408 obj->data.mixerbar.h,
4409 mixer_get_left(obj->data.mixerbar.
4413 new_bar(p, obj->data.mixerbar.w,
4414 obj->data.mixerbar.h,
4415 mixer_get_right(obj->data.mixerbar.
4421 snprintf(p, p_max_size, "%d", cur->mail_count);
4424 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4425 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4428 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4432 snprintf(p, p_max_size, "%s",
4433 cur->uname_s.nodename);
4436 new_outline(p, obj->data.l);
4440 snprintf(p, p_max_size, "%hu", cur->procs);
4442 snprintf(p, 5, "%hu ",
4445 OBJ(running_processes) {
4447 snprintf(p, p_max_size, "%hu",
4450 snprintf(p, 3, "%hu ",
4454 snprintf(p, p_max_size, "%s", obj->data.s);
4457 new_bg(p, obj->data.l);
4460 new_stippled_hr(p, obj->data.pair.a,
4464 human_readable(cur->swap * 1024, p, 255);
4467 human_readable(cur->swapmax * 1024, p,
4471 if (cur->swapmax == 0) {
4472 strncpy(p, "No swap", 255);
4475 snprintf(p, 255, "%*Lu",
4481 snprintf(p, 4, "%*Lu ",
4489 new_bar(p, obj->data.pair.a,
4491 cur->swapmax ? (cur->swap * 255) /
4492 (cur->swapmax) : 0);
4495 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4498 time_t t = time(NULL);
4499 struct tm *tm = localtime(&t);
4500 setlocale(LC_TIME, "");
4501 strftime(p, p_max_size, obj->data.s, tm);
4504 time_t t = time(NULL);
4505 struct tm *tm = gmtime(&t);
4506 strftime(p, p_max_size, obj->data.s, tm);
4510 if (obj->data.tztime.tz) {
4511 oldTZ = getenv("TZ");
4512 setenv("TZ", obj->data.tztime.tz, 1);
4515 time_t t = time(NULL);
4516 struct tm *tm = localtime(&t);
4517 setlocale(LC_TIME, "");
4518 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4520 setenv("TZ", oldTZ, 1);
4525 // Needless to free oldTZ since getenv gives ptr to static data
4528 human_readable(obj->data.net->recv, p,
4532 human_readable(obj->data.net->trans, p,
4536 snprintf(p, p_max_size, "%d", total_updates);
4540 snprintf(p, p_max_size, "%d",
4541 (int) (obj->data.net->
4545 snprintf(p, 5, "%d ",
4546 (int) (obj->data.net->
4552 snprintf(p, p_max_size, "%.1f",
4554 trans_speed / 1024.0);
4556 snprintf(p, 8, "%.1f ",
4558 trans_speed / 1024.0);
4562 if (obj->data.net->trans_speed == 0)
4563 obj->data.net->trans_speed = 0.01;
4565 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4566 (obj->data.net->trans_speed /
4567 1024.0), obj->e, 1);
4570 format_seconds_short(p, p_max_size,
4574 format_seconds(p, p_max_size, (int) cur->uptime);
4577 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
4579 snprintf(p, p_max_size, "%s", get_apm_adapter());
4581 OBJ(apm_battery_life) {
4583 msg = get_apm_battery_life();
4584 snprintf(p, p_max_size, "%s", msg);
4587 OBJ(apm_battery_time) {
4589 msg = get_apm_battery_time();
4590 snprintf(p, p_max_size, "%s", msg);
4593 #endif /* __FreeBSD__ */
4597 snprintf(p, p_max_size, "%s", cur->mpd.title);
4600 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4603 snprintf(p, p_max_size, "%s", cur->mpd.album);
4606 snprintf(p, p_max_size, "%s", cur->mpd.random);
4609 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4612 snprintf(p, p_max_size, "%s", cur->mpd.track);
4615 snprintf(p, p_max_size, "%s", cur->mpd.name);
4618 snprintf(p, p_max_size, "%s", cur->mpd.file);
4621 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4624 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4627 snprintf(p, p_max_size, "%s", cur->mpd.status);
4630 int days = 0, hours = 0, minutes =
4632 int tmp = cur->mpd.elapsed;
4633 while (tmp >= 86400) {
4637 while (tmp >= 3600) {
4647 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4648 days, hours, minutes,
4651 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4654 snprintf(p, p_max_size, "%i:%02i", minutes,
4658 int days = 0, hours = 0, minutes =
4660 int tmp = cur->mpd.length;
4661 while (tmp >= 86400) {
4665 while (tmp >= 3600) {
4675 snprintf(p, p_max_size,
4676 "%i days %i:%02i:%02i",
4677 days, hours, minutes,
4680 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4683 snprintf(p, p_max_size, "%i:%02i", minutes,
4687 snprintf(p, p_max_size, "%2.0f",
4688 cur->mpd.progress * 100);
4691 new_bar(p, obj->data.pair.a,
4693 (int) (cur->mpd.progress *
4697 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4698 snprintf(p, p_max_size, "%s", cur->mpd.file);
4700 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4706 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4709 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4712 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4715 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4717 OBJ(xmms2_comment) {
4718 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4720 OBJ(xmms2_decoder) {
4721 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4723 OBJ(xmms2_transport) {
4724 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4727 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4730 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4733 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4735 OBJ(xmms2_tracknr) {
4736 if (cur->xmms2.tracknr != -1)
4737 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4739 OBJ(xmms2_bitrate) {
4740 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4743 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4746 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4748 OBJ(xmms2_elapsed) {
4749 int tmp = cur->xmms2.elapsed;
4750 snprintf(p, p_max_size, "%02d:%02d",
4751 tmp / 60000, (tmp / 1000) % 60);
4753 OBJ(xmms2_duration) {
4754 int tmp = cur->xmms2.duration;
4755 snprintf(p, p_max_size, "%02d:%02d",
4756 tmp / 60000, (tmp / 1000) % 60);
4758 OBJ(xmms2_percent) {
4759 snprintf(p, p_max_size, "%2.0f",
4760 cur->xmms2.progress * 100);
4763 new_bar(p, obj->data.pair.a,
4765 (int) (cur->xmms2.progress *
4769 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4770 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4772 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4777 OBJ(audacious_status) {
4778 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4780 OBJ(audacious_title) {
4781 snprintf(p, cur->audacious.max_title_len > 0 ?
4782 cur->audacious.max_title_len : p_max_size, "%s",
4783 cur->audacious.items[AUDACIOUS_TITLE]);
4785 OBJ(audacious_length) {
4786 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4788 OBJ(audacious_length_seconds) {
4789 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4791 OBJ(audacious_position) {
4792 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4794 OBJ(audacious_position_seconds) {
4795 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4797 OBJ(audacious_bitrate) {
4798 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4800 OBJ(audacious_frequency) {
4801 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4803 OBJ(audacious_channels) {
4804 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4806 OBJ(audacious_filename) {
4807 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4809 OBJ(audacious_playlist_length) {
4810 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4812 OBJ(audacious_playlist_position) {
4813 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4815 OBJ(audacious_bar) {
4817 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4818 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4819 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4824 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4827 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4830 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4833 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4836 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4839 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4843 if (obj->data.top.type == TOP_NAME
4844 && obj->data.top.num >= 0
4845 && obj->data.top.num < 10) {
4846 // if we limit the buffer and add a bunch of space after, it stops the thing from
4847 // moving other shit around, which is really fucking annoying
4848 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4849 } else if (obj->data.top.type == TOP_CPU
4850 && obj->data.top.num >= 0
4851 && obj->data.top.num < 10) {
4852 snprintf(p, 7, "%3.2f ",
4853 cur->cpu[obj->data.top.
4855 } else if (obj->data.top.type == TOP_PID
4856 && obj->data.top.num >= 0
4857 && obj->data.top.num < 10) {
4858 snprintf(p, 8, "%i ",
4859 cur->cpu[obj->data.top.
4861 } else if (obj->data.top.type == TOP_MEM
4862 && obj->data.top.num >= 0
4863 && obj->data.top.num < 10) {
4864 snprintf(p, 7, "%3.2f ",
4865 cur->cpu[obj->data.top.
4870 if (obj->data.top.type == TOP_NAME
4871 && obj->data.top.num >= 0
4872 && obj->data.top.num < 10) {
4873 // if we limit the buffer and add a bunch of space after, it stops the thing from
4874 // moving other shit around, which is really fucking annoying
4877 cur->memu[obj->data.top.
4879 } else if (obj->data.top.type == TOP_CPU
4880 && obj->data.top.num >= 0
4881 && obj->data.top.num < 10) {
4882 snprintf(p, 7, "%3.2f ",
4883 cur->memu[obj->data.top.
4885 } else if (obj->data.top.type == TOP_PID
4886 && obj->data.top.num >= 0
4887 && obj->data.top.num < 10) {
4888 snprintf(p, 8, "%i ",
4889 cur->memu[obj->data.top.
4891 } else if (obj->data.top.type == TOP_MEM
4892 && obj->data.top.num >= 0
4893 && obj->data.top.num < 10) {
4894 snprintf(p, 7, "%3.2f ",
4895 cur->memu[obj->data.top.
4902 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4903 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4905 obj->data.tail.last_update = current_update_time;
4909 fp = fopen(obj->data.tail.logfile, "rt");
4911 /* Send one message, but do not consistently spam on
4912 * missing logfiles. */
4913 if(obj->data.tail.readlines != 0) {
4914 ERR("tail logfile failed to open");
4915 strcpy(obj->data.tail.buffer, "Logfile Missing");
4917 obj->data.tail.readlines = 0;
4918 snprintf(p, p_max_size, "Logfile Missing");
4921 obj->data.tail.readlines = 0;
4922 /* -1 instead of 0 to avoid counting a trailing newline */
4923 fseek(fp, -1, SEEK_END);
4924 bsize = ftell(fp) + 1;
4925 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4926 nl = rev_fcharfind(fp, '\n', iter);
4930 obj->data.tail.readlines = iter;
4931 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
4932 fseek(fp, 0, SEEK_SET);
4935 fseek(fp, nl+1, SEEK_SET);
4938 /* Make sure bsize is at least 1 byte smaller than
4939 * the buffer max size. */
4940 if(bsize > (long)((text_buffer_size*20) - 1)) {
4941 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
4942 bsize = text_buffer_size*20 - 1;
4944 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
4947 /* Clean up trailing newline, make sure the buffer
4948 * is null terminated. */
4949 if(obj->data.tail.buffer[bsize-1] == '\n')
4950 obj->data.tail.buffer[bsize-1] = '\0';
4952 obj->data.tail.buffer[bsize] = '\0';
4953 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4956 strcpy(obj->data.tail.buffer, "Logfile Empty");
4957 snprintf(p, p_max_size, "Logfile Empty");
4960 } /* if cur_upd_time >= */
4962 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4966 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4967 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4969 obj->data.tail.last_update = current_update_time;
4973 fp = fopen(obj->data.tail.logfile, "rt");
4975 /* Send one message, but do not consistently spam on
4976 * missing logfiles. */
4977 if(obj->data.tail.readlines != 0) {
4978 ERR("head logfile failed to open");
4979 strcpy(obj->data.tail.buffer, "Logfile Missing");
4981 obj->data.tail.readlines = 0;
4982 snprintf(p, p_max_size, "Logfile Missing");
4984 obj->data.tail.readlines = 0;
4985 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4986 nl = fwd_fcharfind(fp, '\n', iter);
4990 obj->data.tail.readlines = iter;
4991 /* Make sure nl is at least 1 byte smaller than
4992 * the buffer max size. */
4993 if(nl > (long)((text_buffer_size*20) - 1)) {
4994 nl = text_buffer_size*20 - 1;
4996 nl = fread(obj->data.tail.buffer, 1, nl, fp);
4999 /* Clean up trailing newline, make sure the buffer
5000 * is null terminated. */
5001 if (obj->data.tail.buffer[nl-1] == '\n') {
5002 obj->data.tail.buffer[nl-1] = '\0';
5005 obj->data.tail.buffer[nl] = '\0';
5007 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5010 strcpy(obj->data.tail.buffer, "Logfile Empty");
5011 snprintf(p, p_max_size, "Logfile Empty");
5013 } /* if fp == null */
5014 } /* cur_upd_time >= */
5016 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5019 #ifdef TCP_PORT_MONITOR
5022 /* grab a pointer to this port monitor */
5023 tcp_port_monitor_t * p_monitor =
5024 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5025 obj->data.tcp_port_monitor.port_range_begin,
5026 obj->data.tcp_port_monitor.port_range_end );
5028 snprintf(p, p_max_size, "monitor not found");
5032 /* now grab the text of interest */
5033 if ( peek_tcp_port_monitor( p_monitor,
5034 obj->data.tcp_port_monitor.item,
5035 obj->data.tcp_port_monitor.connection_index,
5036 p, p_max_size ) != 0 )
5038 snprintf(p, p_max_size, "monitor peek error");
5047 iconv_converting = 1;
5048 iconv_selected = obj->a;
5053 iconv_converting = 0;
5059 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5061 OBJ(entropy_poolsize)
5063 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5067 double entropy_perc;
5068 entropy_perc = (double)cur->entropy.entropy_avail /
5069 (double)cur->entropy.poolsize;
5070 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5078 unsigned int a = strlen(p);
5081 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5083 size_t dummy1, dummy2;
5084 char *ptr = buff_in;
5087 dummy1 = dummy2 = a;
5089 strncpy(buff_in, p, P_MAX_SIZE);
5091 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5092 while (dummy1 > 0) {
5093 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5095 ERR("Iconv codeset conversion failed");
5100 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5111 double current_update_time, last_update_time;
5113 static void generate_text()
5115 struct information *cur = &info;
5123 current_update_time = get_time();
5126 /* fix diskio rates to b/s (use update_interval */
5127 diskio_read_value = diskio_read_value / update_interval;
5128 diskio_write_value = diskio_write_value / update_interval;
5129 diskio_value = diskio_value / update_interval;
5132 /* add things to the buffer */
5138 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5140 if (stuff_in_upper_case) {
5151 last_update_time = current_update_time;
5158 static void set_font()
5162 if (window.xftdraw != NULL) {
5163 XftDrawDestroy(window.xftdraw);
5165 window.xftdraw = XftDrawCreate(display, window.drawable,
5166 DefaultVisual(display,
5168 DefaultColormap(display,
5173 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5179 static inline int get_string_width(const char *s)
5182 return *s ? calc_text_width(s, strlen(s)) : 0;
5188 static inline int get_string_width_special(char *s)
5201 if (*p == SPECIAL_CHAR) {
5202 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5203 for (i = 0; i < strlen(p); i++) {
5204 *(p + i) = *(p + i + 1);
5206 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5207 width += specials[special_index+index].width;
5214 if (strlen(final) > 1) {
5215 width += calc_text_width(final, strlen(final));
5225 static void text_size_updater(char *s);
5227 int last_font_height;
5228 static void update_text_area()
5232 /* update text size if it isn't fixed */
5237 text_width = minimum_width;
5240 last_font_height = font_height();
5241 for_each_line(text_buffer, text_size_updater);
5243 if (text_height < minimum_height)
5244 text_height = minimum_height;
5245 if (text_width > maximum_width && maximum_width > 0)
5246 text_width = maximum_width;
5249 /* get text position on workarea */
5250 switch (text_alignment) {
5257 x = workarea[2] - text_width - gap_x;
5264 y = workarea[3] - text_height - gap_y;
5268 x = workarea[2] - text_width - gap_x;
5269 y = workarea[3] - text_height - gap_y;
5273 case NONE: // Let the WM manage the window
5284 if (own_window && !fixed_pos) {
5287 text_start_x = border_margin + 1;
5288 text_start_y = border_margin + 1;
5289 window.x = x - border_margin - 1;
5290 window.y = y - border_margin - 1;
5294 /* If window size doesn't match to workarea's size, then window
5295 * probably includes panels (gnome).
5296 * Blah, doesn't work on KDE. */
5297 if (workarea[2] != window.width
5298 || workarea[3] != window.height) {
5312 static int cur_x, cur_y; /* current x and y for drawing */
5313 static int draw_mode; /* FG, BG or OUTLINE */
5314 static long current_color;
5317 static void text_size_updater(char *s)
5321 /* get string widths and skip specials */
5324 if (*p == SPECIAL_CHAR) {
5326 w += get_string_width(s);
5329 if (specials[special_index].type == BAR
5330 || specials[special_index].type == GRAPH) {
5331 w += specials[special_index].width;
5332 if (specials[special_index].height > last_font_height) {
5333 last_font_height = specials[special_index].height;
5334 last_font_height += font_ascent();
5336 } else if (specials[special_index].type == OFFSET) {
5337 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5338 } else if (specials[special_index].type == VOFFSET) {
5339 last_font_height += specials[special_index].arg;
5340 } else if (specials[special_index].type == GOTO) {
5341 if (specials[special_index].arg >= 0)
5342 w += (int)specials[special_index].arg - cur_x;
5343 } else if (specials[special_index].type == TAB) {
5344 int start = specials[special_index].arg;
5345 int step = specials[special_index].width;
5346 if (!step || step < 0)
5348 w += step - (cur_x - text_start_x - start) % step;
5349 } else if (specials[special_index].type == FONT) {
5350 selected_font = specials[special_index].font_added;
5351 if (font_height() > last_font_height) {
5352 last_font_height = font_height();
5361 w += get_string_width(s);
5362 if (w > text_width) {
5365 if (text_width > maximum_width && maximum_width) {
5366 text_width = maximum_width;
5369 text_height += last_font_height;
5370 last_font_height = font_height();
5374 static inline void set_foreground_color(long c)
5377 XSetForeground(display, window.gc, c);
5381 static void draw_string(const char *s)
5385 int i, i2, pos, width_of_s;
5388 width_of_s = get_string_width(s);
5389 if (out_to_console) {
5391 fflush(stdout); /* output immediately, don't buffer */
5393 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5394 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5395 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5399 snprintf(space, 2, " ");
5401 max = ((text_width - width_of_s) / get_string_width(space));
5404 * This code looks for tabs in the text and coverts them to spaces.
5405 * The trick is getting the correct number of spaces,
5406 * and not going over the window's size without forcing
5407 * the window larger.
5409 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5410 if (tmpstring1[i] == '\t') // 9 is ascii tab
5414 i2 < (8 - (1 + pos) % 8) && added <= max;
5417 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5418 fprintf(stderr,"buffer overrun detected\n");
5420 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5425 if (tmpstring1[i] != 9) {
5427 if ( pos > TEXT_BUFFER_SIZE-1 )
5428 fprintf(stderr,"buffer overrun detected\n");
5430 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5436 if (text_width == maximum_width) {
5437 /* this means the text is probably pushing the limit, so we'll chop it */
5438 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5439 tmpstring2[strlen(tmpstring2)-1] = '\0';
5449 c.pixel = current_color;
5450 XQueryColor(display, DefaultColormap(display, screen), &c);
5453 c2.color.red = c.red;
5454 c2.color.green = c.green;
5455 c2.color.blue = c.blue;
5456 c2.color.alpha = fonts[selected_font].font_alpha;
5458 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5459 cur_x, cur_y, (XftChar8 *) s,
5462 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5463 cur_x, cur_y, (XftChar8 *) s,
5469 XDrawString(display, window.drawable, window.gc,
5470 cur_x, cur_y, s, strlen(s));
5472 cur_x += width_of_s;
5474 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5477 long redmask, greenmask, bluemask;
5479 void set_up_gradient()
5482 colour_depth = DisplayPlanes(display, screen);
5486 if (colour_depth != 24 && colour_depth != 16) {
5487 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5493 for(i = (colour_depth / 3)-1; i>=0; i--) {
5495 greenmask |= 1 << i;
5498 if (colour_depth%3 == 1) {
5499 greenmask |= 1 << (colour_depth / 3);
5501 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5502 greenmask = greenmask << (colour_depth / 3);
5505 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 */
5507 int red1, green1, blue1; // first colour
5508 int red2, green2, blue2; // second colour
5509 int red3 = 0, green3 = 0, blue3 = 0; // difference
5510 short redshift = (2*colour_depth / 3 + colour_depth%3);
5511 short greenshift = (colour_depth / 3);
5512 red1 = (first_colour & redmask) >> redshift;
5513 green1 = (first_colour & greenmask) >> greenshift;
5514 blue1 = first_colour & bluemask;
5515 red2 = (last_colour & redmask) >> redshift;
5516 green2 = (last_colour & greenmask) >> greenshift;
5517 blue2 = last_colour & bluemask;
5524 if (green1 > green2) {
5527 if (green1 < green2) {
5530 if (blue1 > blue2) {
5533 if (blue1 < blue2) {
5548 if (red1 > bluemask) {
5551 if (green1 > bluemask) {
5554 if (blue1 > bluemask) {
5557 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5561 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5562 if (colour_depth == 0) {
5565 int red1, green1, blue1; // first colour
5566 int red2, green2, blue2; // second colour
5567 long redshift = (2*colour_depth / 3 + colour_depth%3);
5568 long greenshift = (colour_depth / 3);
5569 int red3 = 0, green3 = 0, blue3 = 0; // difference
5570 red1 = (first_colour & redmask) >> redshift;
5571 green1 = (first_colour & greenmask) >> greenshift;
5572 blue1 = first_colour & bluemask;
5573 red2 = (last_colour & redmask) >> redshift;
5574 green2 = (last_colour & greenmask) >> greenshift;
5575 blue2 = last_colour & bluemask;
5576 red3 = abs(red1 - red2);
5577 green3 = abs(green1 - green2);
5578 blue3 = abs(blue1 - blue2);
5587 static void draw_line(char *s)
5591 cur_x = text_start_x;
5592 cur_y += font_ascent();
5594 short font_h = font_height();
5596 /* find specials and draw stuff */
5599 if (*p == SPECIAL_CHAR) {
5602 /* draw string before special */
5609 switch (specials[special_index].type) {
5610 case HORIZONTAL_LINE:
5613 specials[special_index].height;
5614 int mid = font_ascent() / 2;
5615 w = text_start_x + text_width -
5618 XSetLineAttributes(display,
5623 XDrawLine(display, window.drawable,
5634 specials[special_index].height;
5636 specials[special_index].arg;
5637 int mid = font_ascent() / 2;
5638 char ss[2] = { s, s };
5639 w = text_start_x + text_width -
5642 XSetLineAttributes(display,
5647 XSetDashes(display, window.gc, 0,
5649 XDrawLine(display, window.drawable,
5659 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5663 specials[special_index].height;
5665 specials[special_index].arg;
5666 int by = cur_y - (font_ascent() / 2) - 1;
5667 if (h < font_height()) {
5670 w = specials[special_index].width;
5673 text_width - cur_x - 1;
5677 XSetLineAttributes(display,
5683 XDrawRectangle(display,
5687 XFillRectangle(display,
5691 w * bar_usage / 255,
5693 if (specials[special_index].
5695 && specials[special_index].
5699 [special_index].height;
5706 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5710 specials[special_index].height;
5711 unsigned long last_colour = current_color;
5712 int by = cur_y - (font_ascent()/2) - 1;
5713 if (h < font_height()) {
5716 w = specials[special_index].width;
5718 w = text_start_x + text_width - cur_x - 1;
5721 if (draw_graph_borders) {
5722 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5723 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5725 XSetLineAttributes(display,
5732 int gradient_size = 0;
5733 float gradient_factor = 0;
5734 float gradient_update = 0;
5735 unsigned long tmpcolour = current_color;
5736 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5737 tmpcolour = specials[special_index].last_colour;
5738 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5739 gradient_factor = (float)gradient_size / (w - 2);
5741 for (i = w - 2; i > -1; i--) {
5742 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5743 XSetForeground(display, window.gc, tmpcolour);
5744 gradient_update += gradient_factor;
5745 while (gradient_update > 0) {
5746 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5750 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5753 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 */
5755 if (specials[special_index].
5757 && specials[special_index].
5761 [special_index].height;
5763 /* if (draw_mode == BG) {
5764 set_foreground_color(default_bg_color);
5766 else if (draw_mode == OUTLINE) {
5767 set_foreground_color(default_out_color);
5769 set_foreground_color(default_fg_color);
5771 set_foreground_color(last_colour);
5777 int old = font_ascent();
5778 cur_y -= font_ascent();
5779 selected_font = specials[special_index].font_added;
5780 if (cur_y + font_ascent() < cur_y + old) {
5783 cur_y += font_ascent();
5789 if (draw_mode == FG)
5790 set_foreground_color(specials
5796 if (draw_mode == BG)
5797 set_foreground_color(specials
5803 if (draw_mode == OUTLINE)
5804 set_foreground_color(specials
5810 w += specials[special_index].arg;
5814 cur_y += specials[special_index].arg;
5818 if (specials[special_index].arg >= 0)
5819 cur_x = (int)specials[special_index].arg;
5824 int start = specials[special_index].arg;
5825 int step = specials[special_index].width;
5826 if (!step || step < 0)
5828 w = step - (cur_x - text_start_x - start) % step;
5834 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5835 /*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);*/
5836 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5837 cur_x = pos_x - specials[special_index].arg;
5844 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5845 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5846 /*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);*/
5848 specials[special_index].arg)
5851 [special_index].arg;
5868 if (cur_y_add > 0) {
5870 cur_y -= font_descent();
5875 cur_y += font_descent();
5879 static void draw_text()
5882 cur_y = text_start_y;
5885 if (draw_borders && border_width > 0) {
5886 unsigned int b = (border_width + 1) / 2;
5888 if (stippled_borders) {
5890 { stippled_borders, stippled_borders };
5891 XSetLineAttributes(display, window.gc,
5892 border_width, LineOnOffDash,
5893 CapButt, JoinMiter);
5894 XSetDashes(display, window.gc, 0, ss, 2);
5896 XSetLineAttributes(display, window.gc,
5897 border_width, LineSolid,
5898 CapButt, JoinMiter);
5901 XDrawRectangle(display, window.drawable, window.gc,
5902 text_start_x - border_margin + b,
5903 text_start_y - border_margin + b,
5904 text_width + border_margin * 2 - 1 - b * 2,
5905 text_height + border_margin * 2 - 1 -
5912 for_each_line(text_buffer, draw_line);
5915 static void draw_stuff()
5919 if (draw_shades && !draw_outline) {
5922 set_foreground_color(default_bg_color);
5932 for (i = -1; i < 2; i++)
5933 for (j = -1; j < 2; j++) {
5934 if (i == 0 && j == 0)
5938 set_foreground_color(default_out_color);
5939 draw_mode = OUTLINE;
5946 set_foreground_color(default_fg_color);
5954 swap.swap_window = window.window;
5955 swap.swap_action = XdbeBackground;
5956 XdbeSwapBuffers(display, &swap, 1);
5962 static void clear_text(int exposures)
5966 return; /* The swap action is XdbeBackground, which clears */
5970 /* there is some extra space for borders and outlines */
5971 XClearArea(display, window.window,
5972 text_start_x - border_margin - 1,
5973 text_start_y - border_margin - 1,
5974 text_width + border_margin * 2 + 2,
5975 text_height + border_margin * 2 + 2,
5976 exposures ? True : 0);
5981 static int need_to_update;
5983 /* update_text() generates new text and clears old text area */
5984 static void update_text()
5993 static void main_loop()
5995 #ifdef SIGNAL_BLOCKING
5996 sigset_t newmask, oldmask;
5998 sigemptyset(&newmask);
5999 sigaddset(&newmask,SIGINT);
6000 sigaddset(&newmask,SIGTERM);
6001 sigaddset(&newmask,SIGUSR1);
6005 Region region = XCreateRegion();
6007 int event_base, error_base;
6008 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6009 ERR("Xdamage extension unavailable");
6011 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6012 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6013 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6014 #endif /* HAVE_XDAMAGE */
6018 while (total_run_times == 0 || info.looped < total_run_times) {
6021 #ifdef SIGNAL_BLOCKING
6022 /* block signals. we will inspect for pending signals later */
6023 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6024 CRIT_ERR("unable to sigprocmask()");
6030 /* wait for X event or timeout */
6032 if (!XPending(display)) {
6037 update_interval - (get_time() -
6043 tv.tv_sec = (long) t;
6044 tv.tv_usec = (long) (t * 1000000) % 1000000;
6046 FD_SET(ConnectionNumber(display), &fdsr);
6049 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6052 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6057 ERR("can't select(): %s",
6068 if (need_to_update) {
6070 int wx = window.x, wy = window.y;
6078 /* resize window if it isn't right size */
6080 (text_width + border_margin * 2 + 1 !=
6082 || text_height + border_margin * 2 + 1 !=
6086 border_margin * 2 + 1;
6089 border_margin * 2 + 1;
6090 XResizeWindow(display,
6095 set_transparent_background(window.window);
6099 /* move window if it isn't in right position */
6102 || window.y != wy)) {
6103 XMoveWindow(display, window.window,
6104 window.x, window.y);
6114 r.x = text_start_x - border_margin;
6115 r.y = text_start_y - border_margin;
6116 r.width = text_width + border_margin * 2;
6117 r.height = text_height + border_margin * 2;
6118 XUnionRectWithRegion(&r, region, region);
6123 /* handle X events */
6125 while (XPending(display)) {
6127 XNextEvent(display, &ev);
6134 r.width = ev.xexpose.width;
6135 r.height = ev.xexpose.height;
6136 XUnionRectWithRegion(&r, region,
6142 case ReparentNotify:
6143 /* set background to ParentRelative for all parents */
6145 set_transparent_background(window.
6150 case ConfigureNotify:
6152 /* if window size isn't what expected, set fixed size */
6153 if (ev.xconfigure.width !=
6155 || ev.xconfigure.height !=
6157 if (window.width != 0
6158 && window.height != 0)
6161 /* clear old stuff before screwing up size and pos */
6167 if (XGetWindowAttributes(display, window.window, &attrs)) {
6182 border_margin * 2 - 1;
6185 border_margin * 2 - 1;
6186 if (text_width > maximum_width && maximum_width > 0)
6187 text_width = maximum_width;
6190 /* if position isn't what expected, set fixed pos, total_updates
6191 * avoids setting fixed_pos when window is set to weird locations
6193 /*if (total_updates >= 2 this is broken
6195 && (window.x != ev.xconfigure.x
6198 && (ev.xconfigure.x != 0
6199 || ev.xconfigure.y != 0)) {
6209 /* if an ordinary window with decorations */
6210 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6212 /* allow conky to hold input focus.*/
6217 /* forward the click to the desktop window */
6218 XUngrabPointer(display, ev.xbutton.time);
6219 ev.xbutton.window = window.desktop;
6220 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6221 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6229 /* if an ordinary window with decorations */
6230 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6232 /* allow conky to hold input focus.*/
6237 /* forward the release to the desktop window */
6238 ev.xbutton.window = window.desktop;
6239 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6248 if (ev.type == event_base + XDamageNotify) {
6249 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6250 XFixesSetRegion(display, part, &dev->area, 1);
6251 XFixesUnionRegion(display, region2, region2, part);
6253 #endif /* HAVE_XDAMAGE */
6258 XDamageSubtract(display, damage, region2, None);
6259 XFixesSetRegion(display, region2, 0, 0);
6260 #endif /* HAVE_XDAMAGE */
6262 /* XDBE doesn't seem to provide a way to clear the back buffer without
6263 * interfering with the front buffer, other than passing XdbeBackground
6264 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6265 * redraw the text even if it wasn't part of the exposed area. OTOH,
6266 * if we're not going to call draw_stuff at all, then no swap happens
6267 * and we can safely do nothing.
6270 if (!XEmptyRegion(region)) {
6274 r.x = text_start_x - border_margin;
6275 r.y = text_start_y - border_margin;
6276 r.width = text_width + border_margin * 2;
6277 r.height = text_height + border_margin * 2;
6278 XUnionRectWithRegion(&r, region, region);
6281 XSetRegion(display, window.gc, region);
6284 XftDrawSetClip(window.xftdraw, region);
6290 XDestroyRegion(region);
6291 region = XCreateRegion();
6295 #ifdef SIGNAL_BLOCKING
6296 /* unblock signals of interest and let handler fly */
6297 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6298 CRIT_ERR("unable to sigprocmask()");
6301 switch(g_signal_pending) {
6304 ERR("received SIGUSR1. reloading the config file.");
6311 ERR("received SIGINT or SIGTERM to terminate. bye!");
6314 XDestroyRegion(region);
6317 return; /* return from main_loop */
6322 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6323 * but didn't write any code to deal with it. if you don't want to
6324 * handle a signal, don't set a handler on it in the first place. */
6325 if (g_signal_pending)
6326 ERR("ignoring signal (%d)", g_signal_pending);
6333 #if defined(X11) && defined(HAVE_XDAMAGE)
6334 XDamageDestroy(display, damage);
6335 XFixesDestroyRegion(display, region2);
6336 XFixesDestroyRegion(display, part);
6337 XDestroyRegion(region);
6339 #endif /* X11 && HAVE_XDAMAGE */
6342 static void load_config_file(const char *);
6344 /* reload the config file */
6345 void reload_config(void)
6347 timed_thread_destroy_registered_threads ();
6349 if (info.cpu_usage) {
6350 free(info.cpu_usage);
6351 info.cpu_usage = NULL;
6354 #ifdef TCP_PORT_MONITOR
6355 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6358 if (current_config) {
6360 load_config_file(current_config);
6362 /* re-init specials array */
6363 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6364 ERR("failed to realloc specials array");
6369 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6372 #ifdef TCP_PORT_MONITOR
6373 info.p_tcp_port_monitor_collection = NULL;
6376 if (create_audacious_thread() !=0)
6377 CRIT_ERR("unable to create audacious thread!");
6378 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6380 extract_variable_text(text);
6389 timed_thread_destroy_registered_threads ();
6391 if (info.cpu_usage) {
6392 free(info.cpu_usage);
6393 info.cpu_usage = NULL;
6398 XdbeDeallocateBackBufferName(display, window.back_buffer);
6404 XDestroyWindow(display, window.window);
6405 XClearWindow(display, RootWindow(display, screen));
6411 XClearWindow(display, RootWindow(display, screen));
6416 XFreeGC(display, window.gc);
6419 free_text_objects(text_object_count, text_objects);
6420 text_object_count = 0;
6421 text_objects = NULL;
6423 if (text != original_text)
6426 free(current_config);
6427 free(current_mail_spool);
6429 #ifdef TCP_PORT_MONITOR
6430 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6431 info.p_tcp_port_monitor_collection = NULL;
6440 static int string_to_bool(const char *s)
6444 if (strcasecmp(s, "yes") == 0)
6446 if (strcasecmp(s, "true") == 0)
6448 if (strcasecmp(s, "1") == 0)
6453 static enum alignment string_to_alignment(const char *s)
6455 if (strcasecmp(s, "top_left") == 0)
6457 else if (strcasecmp(s, "top_right") == 0)
6459 else if (strcasecmp(s, "bottom_left") == 0)
6461 else if (strcasecmp(s, "bottom_right") == 0)
6462 return BOTTOM_RIGHT;
6463 else if (strcasecmp(s, "tl") == 0)
6465 else if (strcasecmp(s, "tr") == 0)
6467 else if (strcasecmp(s, "bl") == 0)
6469 else if (strcasecmp(s, "br") == 0)
6470 return BOTTOM_RIGHT;
6471 else if (strcasecmp(s, "none") == 0)
6478 static void set_default_configurations(void)
6480 fork_to_background = 0;
6481 total_run_times = 0;
6482 info.cpu_avg_samples = 2;
6483 info.net_avg_samples = 2;
6488 strcpy(info.mpd.host, "localhost");
6489 info.mpd.port = 6600;
6490 info.mpd.status = NULL;
6491 info.mpd.artist = NULL;
6492 info.mpd.album = NULL;
6493 info.mpd.title = NULL;
6494 info.mpd.random = NULL;
6495 info.mpd.track = NULL;
6496 info.mpd.name = NULL;
6497 info.mpd.file = NULL;
6500 info.xmms2.artist = NULL;
6501 info.xmms2.album = NULL;
6502 info.xmms2.title = NULL;
6503 info.xmms2.genre = NULL;
6504 info.xmms2.comment = NULL;
6505 info.xmms2.decoder = NULL;
6506 info.xmms2.transport = NULL;
6507 info.xmms2.url = NULL;
6508 info.xmms2.status = NULL;
6517 default_fg_color = WhitePixel(display, screen);
6518 default_bg_color = BlackPixel(display, screen);
6519 default_out_color = BlackPixel(display, screen);
6520 color0 = default_fg_color;
6521 color1 = default_fg_color;
6522 color2 = default_fg_color;
6523 color3 = default_fg_color;
6524 color4 = default_fg_color;
6525 color5 = default_fg_color;
6526 color6 = default_fg_color;
6527 color7 = default_fg_color;
6528 color8 = default_fg_color;
6529 color9 = default_fg_color;
6532 draw_graph_borders = 1;
6534 set_first_font("6x10");
6542 window.type=TYPE_NORMAL;
6544 strcpy(window.class_name, "Conky");
6546 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6548 stippled_borders = 0;
6551 text_alignment = BOTTOM_LEFT;
6554 free(current_mail_spool);
6557 variable_substitute(MAIL_FILE, buf, 256);
6559 current_mail_spool = strdup(buf);
6563 update_interval = 10.0;
6564 stuff_in_upper_case = 0;
6566 #ifdef TCP_PORT_MONITOR
6567 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6571 static void load_config_file(const char *f)
6573 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6577 set_default_configurations();
6583 char buf[256], *p, *p2, *name, *value;
6585 if (fgets(buf, 256, fp) == NULL)
6590 /* break at comment */
6591 p2 = strchr(p, '#');
6596 while (*p && isspace((int) *p))
6599 continue; /* empty line */
6605 while (*p2 && !isspace((int) *p2))
6608 *p2 = '\0'; /* break at name's end */
6615 while (*p && isspace((int) *p))
6620 p2 = value + strlen(value);
6621 while (isspace((int) *(p2 - 1)))
6627 #define CONF2(a) if (strcasecmp(name, a) == 0)
6628 #define CONF(a) else CONF2(a)
6629 #define CONF3(a,b) \
6630 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6634 CONF2("alignment") {
6636 int a = string_to_alignment(value);
6644 CONF("background") {
6645 fork_to_background = string_to_bool(value);
6649 CONF2("background") {
6650 fork_to_background = string_to_bool(value);
6654 CONF("border_margin") {
6656 border_margin = strtol(value, 0, 0);
6660 CONF("border_width") {
6662 border_width = strtol(value, 0, 0);
6668 color0 = get_x11_color(value);
6674 color1 = get_x11_color(value);
6680 color2 = get_x11_color(value);
6686 color3 = get_x11_color(value);
6692 color4 = get_x11_color(value);
6698 color5 = get_x11_color(value);
6704 color6 = get_x11_color(value);
6710 color7 = get_x11_color(value);
6716 color8 = get_x11_color(value);
6722 color9 = get_x11_color(value);
6726 CONF("default_color") {
6728 default_fg_color = get_x11_color(value);
6732 CONF3("default_shade_color", "default_shadecolor") {
6734 default_bg_color = get_x11_color(value);
6738 CONF3("default_outline_color", "default_outlinecolor") {
6740 default_out_color = get_x11_color(value);
6747 info.mail = parse_mail_args(IMAP, value);
6754 info.mail = parse_mail_args(POP3, value);
6762 strncpy(info.mpd.host, value, 127);
6768 info.mpd.port = strtol(value, 0, 0);
6769 if (info.mpd.port < 1
6770 || info.mpd.port > 0xffff)
6774 CONF("mpd_password") {
6776 strncpy(info.mpd.password, value, 127);
6782 CONF("sensor_device") {
6784 sensor_device = strtol(value, 0, 0);
6789 CONF("cpu_avg_samples") {
6791 cpu_avg_samples = strtol(value, 0, 0);
6792 if (cpu_avg_samples < 1
6793 || cpu_avg_samples > 14)
6802 CONF("net_avg_samples") {
6804 net_avg_samples = strtol(value, 0, 0);
6805 if (net_avg_samples < 1
6806 || net_avg_samples > 14)
6822 CONF("double_buffer") {
6823 use_xdbe = string_to_bool(value);
6827 CONF("override_utf8_locale") {
6828 utf8_mode = string_to_bool(value);
6831 CONF("draw_borders") {
6832 draw_borders = string_to_bool(value);
6834 CONF("draw_graph_borders") {
6835 draw_graph_borders = string_to_bool(value);
6837 CONF("draw_shades") {
6838 draw_shades = string_to_bool(value);
6840 CONF("draw_outline") {
6841 draw_outline = string_to_bool(value);
6844 CONF("out_to_console") {
6845 out_to_console = string_to_bool(value);
6847 CONF("use_spacer") {
6848 use_spacer = string_to_bool(value);
6853 use_xft = string_to_bool(value);
6857 set_first_font(value);
6862 if (value && font_count >= 0)
6863 fonts[0].font_alpha = atof(value)
6872 if (string_to_bool(value))
6873 ERR("Xft not enabled");
6876 /* xftfont silently ignored when no Xft */
6879 /* xftalpha is silently ignored when no Xft */
6884 set_first_font(value);
6893 gap_x = atoi(value);
6899 gap_y = atoi(value);
6904 CONF("mail_spool") {
6907 variable_substitute(value, buf, 256);
6911 if (current_mail_spool)
6912 free(current_mail_spool);
6913 current_mail_spool = strdup(buf);
6919 CONF("minimum_size") {
6922 (value, "%d %d", &minimum_width,
6923 &minimum_height) != 2)
6926 &minimum_width) != 1)
6931 CONF("maximum_width") {
6933 if (sscanf(value, "%d", &maximum_width) != 1)
6939 CONF("no_buffers") {
6940 no_buffers = string_to_bool(value);
6942 CONF("pad_percents") {
6943 pad_percents = atoi(value);
6947 CONF("own_window") {
6949 own_window = string_to_bool(value);
6953 CONF("own_window_class") {
6956 memset(window.class_name,0,sizeof(window.class_name));
6957 strncpy(window.class_name, value, sizeof(window.class_name)-1);
6962 CONF("own_window_title") {
6965 memset(window.title,0,sizeof(window.title));
6966 strncpy(window.title, value, sizeof(window.title)-1);
6971 CONF("own_window_transparent") {
6973 set_transparent = string_to_bool(value);
6977 CONF("own_window_colour") {
6979 background_colour = get_x11_color(value);
6981 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
6984 CONF("own_window_hints") {
6986 char *p_hint, *p_save;
6987 char delim[] = ", ";
6989 /* tokenize the value into individual hints */
6990 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
6992 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
6993 if (strncmp(p_hint,"undecorate",10) == 0)
6994 SET_HINT(window.hints,HINT_UNDECORATED);
6995 else if (strncmp(p_hint,"below",5) == 0)
6996 SET_HINT(window.hints,HINT_BELOW);
6997 else if (strncmp(p_hint,"above",5) == 0)
6998 SET_HINT(window.hints,HINT_ABOVE);
6999 else if (strncmp(p_hint,"sticky",6) == 0)
7000 SET_HINT(window.hints,HINT_STICKY);
7001 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7002 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7003 else if (strncmp(p_hint,"skip_pager",10) == 0)
7004 SET_HINT(window.hints,HINT_SKIP_PAGER);
7008 p_hint=strtok_r(NULL, delim, &p_save);
7010 while (p_hint!=NULL);
7015 CONF("own_window_type") {
7017 if (strncmp(value,"normal",6)==0)
7018 window.type = TYPE_NORMAL;
7019 else if (strncmp(value,"desktop",7)==0)
7020 window.type = TYPE_DESKTOP;
7021 else if (strncmp(value,"override",8)==0)
7022 window.type = TYPE_OVERRIDE;
7030 CONF("stippled_borders") {
7032 stippled_borders = strtol(value, 0, 0);
7034 stippled_borders = 4;
7038 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7041 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7043 CONF("update_interval") {
7045 update_interval = strtod(value, 0);
7049 CONF("total_run_times") {
7051 total_run_times = strtod(value, 0);
7056 stuff_in_upper_case = string_to_bool(value);
7058 CONF("max_specials") {
7060 max_specials = atoi(value);
7064 CONF("max_user_text") {
7066 max_user_text = atoi(value);
7070 CONF("text_buffer_size") {
7072 text_buffer_size = atoi(value);
7077 if (text != original_text)
7087 int l = strlen(text);
7088 if (fgets(buf, 256, fp) == NULL)
7091 realloc(text, l + strlen(buf)
7095 if (strlen(text) > max_user_text)
7099 text_lines = line + 1;
7102 #ifdef TCP_PORT_MONITOR
7103 CONF("max_port_monitor_connections")
7106 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7107 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7109 /* an error. use default, warn and continue. */
7110 tcp_port_monitor_args.max_port_monitor_connections =
7111 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7114 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7116 /* no error, just use default */
7117 tcp_port_monitor_args.max_port_monitor_connections =
7118 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7120 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7125 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7137 /* : means that character before that takes an argument */
7138 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7151 int main(int argc, char **argv)
7153 struct sigaction act, oact;
7156 memset(&info, 0, sizeof(info) );
7158 #ifdef TCP_PORT_MONITOR
7159 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7162 /* handle command line parameters that don't change configs */
7167 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7168 *s) || ((s = getenv("LANG")) && *s)) {
7169 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7171 ERR("malloc failed");
7173 for (x = 0; x < strlen(s); x++) {
7174 temp[x] = tolower(s[x]);
7176 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7182 if (!setlocale(LC_CTYPE, "")) {
7183 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7187 int c = getopt(argc,
7198 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7199 * though free() does the NULL check itself;), then load optarg value */
7201 free(current_config);
7202 current_config = strdup(optarg);
7207 ("Usage: %s [OPTION]...\n"
7208 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7209 "window. Command line options will override configurations defined in config\n"
7212 " -c FILE config file to load instead of "
7215 " -d daemonize, fork to background\n"
7218 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7219 " -f FONT font to use\n"
7221 " -o create own window to draw\n"
7224 " -b double buffer (prevents flickering)\n"
7226 " -w WIN_ID window id to draw\n"
7227 " -x X x position\n"
7228 " -y Y y position\n"
7230 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7231 " -u SECS update interval\n"
7232 " -i NUM number of times to update Conky\n", argv[0]);
7236 window.window = strtol(optarg, 0, 0);
7245 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7249 /* load current_config or CONFIG_FILE */
7252 if (current_config == NULL) {
7253 /* load default config file */
7256 variable_substitute(CONFIG_FILE, buf, 256);
7259 current_config = strdup(buf);
7263 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7264 load_config_file(current_config);
7266 set_default_configurations();
7269 /* init specials array */
7270 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7271 ERR("failed to create specials array");
7274 if (current_mail_spool == NULL) {
7276 variable_substitute(MAIL_FILE, buf, 256);
7279 current_mail_spool = strdup(buf);
7283 /* handle other command line arguments */
7285 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7286 optind = optreset = 1;
7291 #if defined(__FreeBSD__)
7292 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7293 O_RDONLY, "kvm_open")) == NULL)
7294 CRIT_ERR( "cannot read kvm");
7298 int c = getopt(argc,
7306 fork_to_background = 1;
7311 set_first_font(optarg);
7314 text_alignment = string_to_alignment(optarg);
7329 if (text != original_text)
7331 text = strdup(optarg);
7332 convert_escapes(text);
7336 update_interval = strtod(optarg, 0);
7340 total_run_times = strtod(optarg, 0);
7344 gap_x = atoi(optarg);
7348 gap_y = atoi(optarg);
7362 /* generate text and get initial size */
7363 extract_variable_text(text);
7364 if (text != original_text) {
7369 if (fork_to_background) {
7373 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7379 fprintf(stderr,"\n"); fflush(stderr);
7383 /* parent process */
7384 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7391 update_text_area(); /* to get initial size of the window */
7395 text_width + border_margin * 2 + 1,
7396 text_height + border_margin * 2 + 1,
7397 set_transparent, background_colour, argv, argc);
7400 update_text_area(); /* to position text/window on screen */
7405 if (own_window && !fixed_pos) {
7406 XMoveWindow(display, window.window, window.x, window.y);
7409 set_transparent_background(window.window);
7420 /* Set signal handlers */
7421 act.sa_handler = signal_handler;
7422 sigemptyset(&act.sa_mask);
7425 act.sa_flags |= SA_RESTART;
7428 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7429 sigaction(SIGUSR1,&act,&oact) < 0 ||
7430 sigaction(SIGTERM,&act,&oact) < 0 )
7432 ERR("error setting signal handler: %s", strerror(errno) );
7436 if (create_audacious_thread() !=0)
7437 CRIT_ERR("unable to create audacious thread!");
7438 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7449 #if defined(__FreeBSD__)
7456 void signal_handler(int sig)
7458 /* signal handler is light as a feather, as it should be.
7459 * we will poll g_signal_pending with each loop of conky
7460 * and do any signal processing there, NOT here. */
7461 g_signal_pending=sig;