2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
28 #include <X11/Xutil.h>
30 #include <X11/extensions/Xdamage.h>
36 #include <sys/types.h>
38 #include <netinet/in.h>
48 #define CONFIG_FILE "$HOME/.conkyrc"
49 #define MAIL_FILE "$MAIL"
50 #define MAX_IF_BLOCK_DEPTH 5
52 /* #define SIGNAL_BLOCKING */
53 #undef SIGNAL_BLOCKING
55 static void print_version()
57 printf("Conky %s compiled %s for %s\n",
58 VERSION, BUILD_DATE, BUILD_ARCH);
61 "\nCompiled in features:\n\n"
65 " * Xdamage extension\n"
66 # endif /* HAVE_XDAMAGE */
68 " * Xdbe extension (double buffer)\n"
69 # endif /* HAVE_XDBE */
75 "\n Music detection:\n"
78 #endif /* AUDACIOUS */
88 "\n General features:\n"
92 #ifdef TCP_PORT_MONITOR
94 #endif /* TCP_PORT_MONITOR */
106 static int text_start_x, text_start_y; /* text start position in window */
107 static int text_width, text_height;
122 char name[TEXT_BUFFER_SIZE];
132 static int selected_font = 0;
133 static int font_count = -1;
134 struct font_list *fonts = NULL;
138 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
139 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
140 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
141 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
145 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
146 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
147 #define font_descent() fonts[selected_font].font->max_bounds.descent
151 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
154 static void set_font();
156 int addfont(const char *data_in)
158 if (font_count > MAX_FONTS) {
159 CRIT_ERR("you don't need that many fonts, sorry.");
162 if (font_count == 0) {
166 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
170 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
172 CRIT_ERR("realloc in addfont");
174 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
175 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
177 fonts[font_count].font_alpha = 0xffff;
180 CRIT_ERR("Oops...looks like something overflowed in addfont().");
185 void set_first_font(const char *data_in)
187 if (font_count < 0) {
188 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
193 if (strlen(data_in) > 1) {
194 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
196 fonts[0].font_alpha = 0xffff;
204 for (i=0;i<=font_count;i++) {
207 XftFontClose(display, fonts[i].xftfont);
211 XFreeFont(display, fonts[i].font);
218 set_first_font("6x10");
222 static void load_fonts()
225 for (i=0; i <= font_count; i++) {
229 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
230 XftFontClose(display, fonts[i].xftfont);
232 if ((fonts[i].xftfont =
233 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
236 ERR("can't load Xft font '%s'", fonts[i].name);
237 if ((fonts[i].xftfont =
238 XftFontOpenName(display, screen,
239 "courier-12")) != NULL)
242 ERR("can't load Xft font '%s'", "courier-12");
244 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
245 CRIT_ERR("can't load font '%s'", "fixed");
252 /* load normal font */
253 /* if (fonts[i].font != NULL)
254 XFreeFont(display, fonts[i].font);*/
256 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
257 ERR("can't load font '%s'", fonts[i].name);
258 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
259 CRIT_ERR("can't load font '%s'", "fixed");
260 printf("loaded fixed?\n");
268 /* default config file */
269 static char *current_config;
271 /* set to 1 if you want all text to be in uppercase */
272 static unsigned int stuff_in_upper_case;
274 /* Update interval */
275 static double update_interval;
277 /* Run how many times? */
278 static unsigned long total_run_times;
281 static int fork_to_background;
283 static int cpu_avg_samples, net_avg_samples;
287 /* Position on the screen */
288 static int text_alignment;
289 static int gap_x, gap_y;
292 static int draw_borders;
293 static int draw_graph_borders;
294 static int stippled_borders;
296 static int draw_shades, draw_outline;
298 static int border_margin, border_width;
300 static long default_fg_color, default_bg_color, default_out_color;
302 /* create own window or draw stuff to root? */
303 static int set_transparent = 0;
307 static int own_window = 0;
308 static int background_colour = 0;
309 /* fixed size/pos is set if wm/user changes them */
310 static int fixed_size = 0, fixed_pos = 0;
313 static int minimum_width, minimum_height;
314 static int maximum_width;
318 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
319 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
321 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
322 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
325 #define CODEPAGE_LENGTH 20
328 char iconv_converting;
329 static iconv_t **iconv_cd = 0;
331 int register_iconv(iconv_t *new_iconv)
334 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
336 iconv_cd = malloc(sizeof(iconv_t *));
339 CRIT_ERR("Out of memory");
341 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
342 if (!iconv_cd[iconv_count]) {
343 CRIT_ERR("Out of memory");
345 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
350 void free_iconv(void)
354 for (i = iconv_count; i < 0; i++) {
370 /* no buffers in used memory? */
373 /* pad percentages to decimals? */
374 static int pad_percents = 0;
376 #ifdef TCP_PORT_MONITOR
377 tcp_port_monitor_collection_args_t tcp_port_monitor_collection_args;
378 tcp_port_monitor_args_t tcp_port_monitor_args;
381 /* Text that is shown */
382 static char original_text[] =
383 "$nodename - $sysname $kernel on $machine\n"
385 "${color grey}Uptime:$color $uptime\n"
386 "${color grey}Frequency (in MHz):$color $freq\n"
387 "${color grey}Frequency (in GHz):$color $freq_g\n"
388 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
389 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
390 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
391 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
393 "${color grey}File systems:\n"
394 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
395 "${color grey}Networking:\n"
396 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
399 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
400 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
403 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
404 "Progress: $xmms2_bar\n"
406 "${color grey}Name PID CPU% MEM%\n"
407 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
408 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
409 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
410 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
411 "${tail /var/log/Xorg.0.log 3}";
413 static char *text = original_text;
416 static int total_updates;
419 static int blockdepth = 0;
420 static int if_jumped = 0;
421 static int blockstart[MAX_IF_BLOCK_DEPTH];
423 int check_mount(char *s)
425 #if defined(__linux__)
427 FILE *mtab = fopen("/etc/mtab", "r");
429 char buf1[256], buf2[128];
430 while (fgets(buf1, 256, mtab)) {
431 sscanf(buf1, "%*s %128s", buf2);
432 if (!strcmp(s, buf2)) {
439 ERR("Could not open mtab");
442 #elif defined(__FreeBSD__)
443 struct statfs *mntbuf;
446 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
447 for (i = mntsize - 1; i >= 0; i--)
448 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
457 static inline int calc_text_width(const char *s, int l)
463 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
465 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
471 return XTextWidth(fonts[selected_font].font, s, l);
476 /* formatted text to render on screen, generated in generate_text(),
477 * drawn in draw_stuff() */
479 static char text_buffer[TEXT_BUFFER_SIZE * 4];
481 /* special stuff in text_buffer */
483 #define SPECIAL_CHAR '\x01'
512 unsigned long first_colour; // for graph gradient
513 unsigned long last_colour;
516 /* create specials array on heap instead of stack with introduction of max_specials */
517 static struct special_t *specials = NULL;
519 static unsigned int special_count;
521 static unsigned int special_index; /* used when drawing */
524 #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? */
526 static struct special_t *new_special(char *buf, int t)
528 if (special_count >= max_specials)
529 CRIT_ERR("too many special things in text");
531 buf[0] = SPECIAL_CHAR;
533 specials[special_count].type = t;
534 return &specials[special_count++];
537 typedef struct tailstring_list {
538 char data[TEXT_BUFFER_SIZE];
539 struct tailstring_list *next;
540 struct tailstring_list *first;
543 void addtail(tailstring ** head, char *data_in)
546 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
552 tmp->first = (*head)->first;
554 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
559 void freetail(tailstring * head)
562 while (head != NULL) {
569 void freelasttail(tailstring * head)
571 tailstring * tmp = head;
573 if (tmp->next == head->first) {
580 while(head != NULL && tmp != NULL) {
586 static void new_bar(char *buf, int w, int h, int usage)
588 struct special_t *s = new_special(buf, BAR);
589 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
594 static const char *scan_bar(const char *args, int *w, int *h)
596 *w = 0; /* zero width means all space that is available */
598 /* bar's argument is either height or height,width */
601 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
602 sscanf(args, "%d %n", h, &n);
609 static char *scan_font(const char *args)
611 if (args && sizeof(args) < 127) {
618 static void new_font(char *buf, char * args) {
620 struct special_t *s = new_special(buf, FONT);
621 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
622 int tmp = selected_font;
623 selected_font = s->font_added = addfont(args);
628 struct special_t *s = new_special(buf, FONT);
629 int tmp = selected_font;
630 selected_font = s->font_added = 0;
637 inline void graph_append(struct special_t *graph, double f)
639 if (!graph->scaled && f > graph->graph_scale) {
640 f = graph->graph_scale;
644 graph->graph_scale = 1;
646 graph->graph[0] = f; /* add new data */
647 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
648 graph->graph[i] = graph->graph[i - 1];
649 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
650 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
655 short colour_depth = 0;
656 void set_up_gradient();
658 /* precalculated: 31/255, and 63/255 */
659 #define CONST_8_TO_5_BITS 0.12156862745098
660 #define CONST_8_TO_6_BITS 0.247058823529412
662 /* adjust color values depending on color depth*/
663 static unsigned int adjust_colors(unsigned int color)
666 if (colour_depth == 0) {
669 if (colour_depth == 16) {
670 r = (color & 0xff0000) >> 16;
671 g = (color & 0xff00) >> 8;
673 color = (int)(r * CONST_8_TO_5_BITS) << 11;
674 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
675 color |= (int)(b * CONST_8_TO_5_BITS);
680 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
682 struct special_t *s = new_special(buf, GRAPH);
684 if (s->graph == NULL) {
685 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
686 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
688 s->graph_width = MAX_GRAPH_DEPTH - 2;
690 s->graph = malloc(s->graph_width * sizeof(double));
691 memset(s->graph, 0, s->graph_width * sizeof(double));
692 s->graph_scale = 100;
695 s->first_colour = adjust_colors(first_colour);
696 s->last_colour = adjust_colors(second_colour);
703 s->graph_width = s->width - 2; // subtract 2 for rectangle around
708 s->graph_scale = scale;
715 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
717 *w = 0; /* zero width means all space that is available */
721 /* graph's argument is either height or height,width */
723 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
724 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
726 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
728 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
731 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
735 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
738 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
742 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
745 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
749 if (sscanf(args, "%d,%d", h, w) < 2) {
752 sscanf(args, "%*s %d,%d", h, w);
758 static inline void new_hr(char *buf, int a)
760 new_special(buf, HORIZONTAL_LINE)->height = a;
763 static inline void new_stippled_hr(char *buf, int a, int b)
765 struct special_t *s = new_special(buf, STIPPLED_HR);
770 static inline void new_fg(char *buf, long c)
772 new_special(buf, FG)->arg = c;
775 static inline void new_bg(char *buf, long c)
777 new_special(buf, BG)->arg = c;
780 static inline void new_outline(char *buf, long c)
782 new_special(buf, OUTLINE)->arg = c;
785 static inline void new_offset(char *buf, long c)
787 new_special(buf, OFFSET)->arg = c;
790 static inline void new_voffset(char *buf, long c)
792 new_special(buf, VOFFSET)->arg = c;
795 static inline void new_alignr(char *buf, long c)
797 new_special(buf, ALIGNR)->arg = c;
800 static inline void new_alignc(char *buf, long c)
802 new_special(buf, ALIGNC)->arg = c;
805 static inline void new_goto(char *buf, long c)
807 new_special(buf, GOTO)->arg = c;
810 static inline void new_tab(char *buf, int a, int b) {
811 struct special_t *s = new_special(buf, TAB);
816 /* quite boring functions */
818 static inline void for_each_line(char *b, void (*f) (char *))
822 for (ps = b, pe = b; *pe; pe++) {
835 static void convert_escapes(char *buf)
837 char *p = buf, *s = buf;
853 /* converts from bytes to human readable format (k, M, G, T) */
854 static void human_readable(long long a, char *buf, int size)
856 // Strange conditional due to possible overflows
857 if(a / 1024 / 1024 / 1024.0 > 1024.0){
858 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
860 else if (a >= 1024 * 1024 * 1024) {
861 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
863 else if (a >= 1024 * 1024) {
864 double m = (a / 1024) / 1024.0;
866 snprintf(buf, size, "%.0fMiB", m);
868 snprintf(buf, size, "%.1fMiB", m);
869 } else if (a >= 1024)
870 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
872 snprintf(buf, size, "%LdB", a);
877 enum text_object_type {
928 #if defined(__linux__)
934 OBJ_i8k_left_fan_status,
935 OBJ_i8k_right_fan_status,
936 OBJ_i8k_left_fan_rpm,
937 OBJ_i8k_right_fan_rpm,
939 OBJ_i8k_buttons_status,
947 #endif /* __linux__ */
974 OBJ_running_processes,
983 OBJ_temp1, /* i2c is used instead in these */
1003 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1005 OBJ_apm_battery_time,
1006 OBJ_apm_battery_life,
1007 #endif /* __FreeBSD__ */
1036 OBJ_xmms2_transport,
1051 OBJ_audacious_status,
1052 OBJ_audacious_title,
1053 OBJ_audacious_length,
1054 OBJ_audacious_length_seconds,
1055 OBJ_audacious_position,
1056 OBJ_audacious_position_seconds,
1057 OBJ_audacious_bitrate,
1058 OBJ_audacious_frequency,
1059 OBJ_audacious_channels,
1060 OBJ_audacious_filename,
1061 OBJ_audacious_playlist_length,
1062 OBJ_audacious_playlist_position,
1073 #ifdef TCP_PORT_MONITOR
1085 OBJ_entropy_poolsize,
1089 struct text_object {
1093 unsigned int c, d, e;
1097 char *s; /* some string */
1098 int i; /* some integer */
1099 long l; /* some other integer */
1100 unsigned int sensor;
1101 struct net_stat *net;
1103 unsigned char loadavg[3];
1104 unsigned int cpu_index;
1105 struct mail_s *mail;
1108 char *tz; /* timezone variable */
1109 char *fmt; /* time display formatting */
1159 timed_thread *p_timed_thread;
1165 #ifdef TCP_PORT_MONITOR
1167 in_port_t port_range_begin; /* starting port to monitor */
1168 in_port_t port_range_end; /* ending port to monitor */
1169 int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
1170 int connection_index; /* 0 to n-1 connections. */
1183 struct text_object_list {
1184 unsigned int text_object_count;
1185 struct text_object *text_objects;
1188 static unsigned int text_object_count;
1189 static struct text_object *text_objects;
1190 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1192 #define MAXDATASIZE 1000
1196 struct mail_s* parse_mail_args(char type, const char *arg) {
1197 struct mail_s *mail;
1198 mail = malloc(sizeof(struct mail_s));
1199 memset(mail, 0, sizeof(struct mail_s));
1201 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1203 ERR("Scanning IMAP args failed");
1204 } else if (type == IMAP) {
1205 ERR("Scanning POP3 args failed");
1208 // see if password needs prompting
1209 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1210 int fp = fileno(stdin);
1211 struct termios term;
1212 tcgetattr(fp, &term);
1213 term.c_lflag &= ~ECHO;
1214 tcsetattr(fp, TCSANOW, &term);
1215 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1216 scanf("%128s", mail->pass);
1218 term.c_lflag |= ECHO;
1219 tcsetattr(fp, TCSANOW, &term);
1221 // now we check for optional args
1222 tmp = strstr(arg, "-i ");
1225 sscanf(tmp, "%f", &mail->interval);
1227 mail->interval = 300; // 5 minutes
1229 tmp = strstr(arg, "-p ");
1232 sscanf(tmp, "%lu", &mail->port);
1235 mail->port = 110; // default pop3 port
1236 } else if (type == IMAP) {
1237 mail->port = 143; // default imap port
1241 tmp = strstr(arg, "-f ");
1244 sscanf(tmp, "%s", mail->folder);
1246 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1249 tmp = strstr(arg, "-e ");
1253 if (tmp[0] == '\'') {
1254 len = strstr(tmp+1, "'") - tmp - 1;
1259 strncpy(mail->command, tmp+1, len);
1261 mail->command[0] = '\0';
1263 mail->p_timed_thread = NULL;
1267 void *imap_thread(struct mail_s* mail)
1269 int sockfd, numbytes;
1270 char recvbuf[MAXDATASIZE];
1271 char sendbuf[MAXDATASIZE];
1274 unsigned int old_unseen = UINT_MAX;
1275 unsigned int old_messages = UINT_MAX;
1277 struct sockaddr_in their_addr; // connector's address information
1278 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1279 herror("gethostbyname");
1284 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1286 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1289 goto next_iteration;
1292 their_addr.sin_family = AF_INET; // host byte order
1293 their_addr.sin_port = htons(mail->port); // short, network byte order
1294 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1295 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1298 (sockfd, (struct sockaddr *) &their_addr,
1299 sizeof(struct sockaddr)) == -1) {
1302 goto next_iteration;
1304 struct timeval timeout;
1307 timeout.tv_sec = 60; // 60 second timeout i guess
1308 timeout.tv_usec = 0;
1310 FD_SET(sockfd, &fdset);
1311 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1314 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1318 goto next_iteration;
1321 ERR("IMAP connection failed: timeout");
1323 goto next_iteration;
1325 recvbuf[numbytes] = '\0';
1326 if (strstr(recvbuf, "* OK") != recvbuf) {
1327 ERR("IMAP connection failed, probably not an IMAP server");
1329 goto next_iteration;
1331 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1332 strncat(sendbuf, mail->user,
1333 MAXDATASIZE - strlen(sendbuf) - 1);
1334 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1335 strncat(sendbuf, mail->pass,
1336 MAXDATASIZE - strlen(sendbuf) - 1);
1337 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1338 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1341 goto next_iteration;
1343 timeout.tv_sec = 60; // 60 second timeout i guess
1344 timeout.tv_usec = 0;
1346 FD_SET(sockfd, &fdset);
1347 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1350 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1354 goto next_iteration;
1357 recvbuf[numbytes] = '\0';
1358 if (strstr(recvbuf, "a1 OK") == NULL) {
1359 ERR("IMAP server login failed: %s", recvbuf);
1361 goto next_iteration;
1363 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1364 strncat(sendbuf, mail->folder,
1365 MAXDATASIZE - strlen(sendbuf) - 1);
1366 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1367 MAXDATASIZE - strlen(sendbuf) - 1);
1368 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1371 goto next_iteration;
1373 timeout.tv_sec = 60; // 60 second timeout i guess
1374 timeout.tv_usec = 0;
1376 FD_SET(sockfd, &fdset);
1377 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1380 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1384 goto next_iteration;
1387 recvbuf[numbytes] = '\0';
1388 if (strstr(recvbuf, "a2 OK") == NULL) {
1389 ERR("IMAP status failed: %s", recvbuf);
1391 goto next_iteration;
1393 // now we get the data
1394 reply = strstr(recvbuf, " (MESSAGES ");
1396 *strchr(reply, ')') = '\0';
1397 if (reply == NULL) {
1398 ERR("Error parsing IMAP response: %s", recvbuf);
1400 goto next_iteration;
1402 timed_thread_lock (mail->p_timed_thread);
1403 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1406 timed_thread_unlock (mail->p_timed_thread);
1408 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1409 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1412 goto next_iteration;
1414 timeout.tv_sec = 60; // 60 second timeout i guess
1415 timeout.tv_usec = 0;
1417 FD_SET(sockfd, &fdset);
1418 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1421 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1425 goto next_iteration;
1428 recvbuf[numbytes] = '\0';
1429 if (strstr(recvbuf, "a3 OK") == NULL) {
1430 ERR("IMAP logout failed: %s", recvbuf);
1432 goto next_iteration;
1435 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1436 if (system(mail->command) == -1) {
1441 old_unseen = mail->unseen;
1442 old_messages = mail->messages;
1444 if (timed_thread_test (mail->p_timed_thread))
1445 timed_thread_exit (mail->p_timed_thread);
1450 void *pop3_thread(struct mail_s *mail)
1452 int sockfd, numbytes;
1453 char recvbuf[MAXDATASIZE];
1454 char sendbuf[MAXDATASIZE];
1457 unsigned int old_unseen = UINT_MAX;
1459 struct sockaddr_in their_addr; // connector's address information
1460 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1461 herror("gethostbyname");
1466 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1468 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1471 goto next_iteration;
1474 their_addr.sin_family = AF_INET; // host byte order
1475 their_addr.sin_port = htons(mail->port); // short, network byte order
1476 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1477 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1480 (sockfd, (struct sockaddr *) &their_addr,
1481 sizeof(struct sockaddr)) == -1) {
1484 goto next_iteration;
1486 struct timeval timeout;
1489 timeout.tv_sec = 60; // 60 second timeout i guess
1490 timeout.tv_usec = 0;
1492 FD_SET(sockfd, &fdset);
1493 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1496 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1500 goto next_iteration;
1503 ERR("POP3 connection failed: timeout\n");
1505 goto next_iteration;
1507 recvbuf[numbytes] = '\0';
1508 if (strstr(recvbuf, "+OK ") != recvbuf) {
1509 ERR("POP3 connection failed, probably not a POP3 server");
1511 goto next_iteration;
1513 strncpy(sendbuf, "USER ", MAXDATASIZE);
1514 strncat(sendbuf, mail->user,
1515 MAXDATASIZE - strlen(sendbuf) - 1);
1516 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1517 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1518 perror("send USER");
1520 goto next_iteration;
1522 timeout.tv_sec = 60; // 60 second timeout i guess
1523 timeout.tv_usec = 0;
1525 FD_SET(sockfd, &fdset);
1526 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1529 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1531 perror("recv USER");
1533 goto next_iteration;
1536 recvbuf[numbytes] = '\0';
1537 if (strstr(recvbuf, "+OK ") == NULL) {
1538 ERR("POP3 server login failed: %s", recvbuf);
1540 goto next_iteration;
1542 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1543 strncat(sendbuf, mail->pass,
1544 MAXDATASIZE - strlen(sendbuf) - 1);
1545 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1546 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1547 perror("send PASS");
1549 goto next_iteration;
1551 timeout.tv_sec = 60; // 60 second timeout i guess
1552 timeout.tv_usec = 0;
1554 FD_SET(sockfd, &fdset);
1555 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1558 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1560 perror("recv PASS");
1562 goto next_iteration;
1565 recvbuf[numbytes] = '\0';
1566 if (strstr(recvbuf, "+OK ") == NULL) {
1567 ERR("POP3 server login failed: %s", recvbuf);
1569 goto next_iteration;
1571 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1572 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1573 perror("send STAT");
1575 goto next_iteration;
1577 timeout.tv_sec = 60; // 60 second timeout i guess
1578 timeout.tv_usec = 0;
1580 FD_SET(sockfd, &fdset);
1581 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1584 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1586 perror("recv STAT");
1588 goto next_iteration;
1591 recvbuf[numbytes] = '\0';
1592 if (strstr(recvbuf, "+OK ") == NULL) {
1593 ERR("POP3 status failed: %s", recvbuf);
1595 goto next_iteration;
1597 // now we get the data
1598 reply = recvbuf + 4;
1599 if (reply == NULL) {
1600 ERR("Error parsing POP3 response: %s", recvbuf);
1602 goto next_iteration;
1604 timed_thread_lock (mail->p_timed_thread);
1605 sscanf(reply, "%lu %lu", &mail->unseen,
1607 timed_thread_unlock (mail->p_timed_thread);
1609 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1610 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1611 perror("send QUIT");
1613 goto next_iteration;
1615 timeout.tv_sec = 60; // 60 second timeout i guess
1616 timeout.tv_usec = 0;
1618 FD_SET(sockfd, &fdset);
1619 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1622 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1624 perror("recv QUIT");
1626 goto next_iteration;
1629 recvbuf[numbytes] = '\0';
1630 if (strstr(recvbuf, "+OK") == NULL) {
1631 ERR("POP3 logout failed: %s", recvbuf);
1633 goto next_iteration;
1636 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1637 if (system(mail->command) == -1) {
1642 old_unseen = mail->unseen;
1644 if (timed_thread_test (mail->p_timed_thread))
1645 timed_thread_exit (mail->p_timed_thread);
1651 void *threaded_exec(struct text_object *obj) {
1653 char *p2 = obj->data.texeci.buffer;
1654 FILE *fp = popen(obj->data.texeci.cmd,"r");
1655 timed_thread_lock (obj->data.texeci.p_timed_thread);
1656 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
1659 if (n2 && p2[n2 - 1] == '\n') {
1663 if (*p2 == '\001') {
1668 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1669 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1670 timed_thread_exit (obj->data.texeci.p_timed_thread);
1675 static struct text_object *new_text_object_internal()
1677 struct text_object *obj = malloc(sizeof(struct text_object));
1678 memset(obj, 0, sizeof(struct text_object));
1682 static void free_text_objects(unsigned int count, struct text_object *objs)
1685 for (i = 0; i < count; i++) {
1686 switch (objs[i].type) {
1688 close(objs[i].data.i);
1691 close(objs[i].data.i);
1694 close(objs[i].data.i2c.fd);
1697 free(objs[i].data.s);
1700 free(objs[i].data.s);
1703 free(objs[i].data.tztime.tz);
1704 free(objs[i].data.tztime.fmt);
1709 case OBJ_imap_unseen:
1710 if (!objs[i].global_mode) {
1711 free(objs[i].data.mail);
1714 case OBJ_imap_messages:
1715 if (!objs[i].global_mode) {
1716 free(objs[i].data.mail);
1722 case OBJ_pop3_unseen:
1723 if (!objs[i].global_mode) {
1724 free(objs[i].data.mail);
1728 if (!objs[i].global_mode) {
1729 free(objs[i].data.mail);
1732 case OBJ_if_existing:
1733 case OBJ_if_mounted:
1734 case OBJ_if_running:
1735 free(objs[i].data.ifblock.s);
1738 free(objs[i].data.tail.logfile);
1739 free(objs[i].data.tail.buffer);
1741 case OBJ_text: case OBJ_font:
1742 free(objs[i].data.s);
1745 free(objs[i].data.s);
1748 free(objs[i].data.s);
1751 free(objs[i].data.s);
1754 free(objs[i].data.s);
1756 /* case OBJ_execibar:
1757 free(objs[i].data.s);
1759 case OBJ_execigraph:
1760 free(objs[i].data.s);
1763 case OBJ_iconv_start:
1769 if (info.mpd.title) {
1770 free(info.mpd.title);
1774 case OBJ_mpd_artist:
1775 if (info.mpd.artist) {
1776 free(info.mpd.artist);
1777 info.mpd.artist = 0;
1781 if (info.mpd.album) {
1782 free(info.mpd.album);
1786 case OBJ_mpd_random:
1787 if (info.mpd.random) {
1788 free(info.mpd.random);
1789 info.mpd.random = 0;
1792 case OBJ_mpd_repeat:
1793 if (info.mpd.repeat) {
1794 free(info.mpd.repeat);
1795 info.mpd.repeat = 0;
1799 if (info.mpd.track) {
1800 free(info.mpd.track);
1805 if (info.mpd.name) {
1806 free(info.mpd.name);
1811 if (info.mpd.file) {
1812 free(info.mpd.file);
1816 case OBJ_mpd_status:
1817 if (info.mpd.status) {
1818 free(info.mpd.status);
1819 info.mpd.status = 0;
1823 if (info.mpd.artist) {
1824 free(info.mpd.artist);
1825 info.mpd.artist = 0;
1827 if (info.mpd.title) {
1828 free(info.mpd.title);
1831 if (info.mpd.file) {
1832 free(info.mpd.file);
1839 case OBJ_xmms2_artist:
1840 if (info.xmms2.artist) {
1841 free(info.xmms2.artist);
1842 info.xmms2.artist = 0;
1845 case OBJ_xmms2_album:
1846 if (info.xmms2.album) {
1847 free(info.xmms2.album);
1848 info.xmms2.album = 0;
1851 case OBJ_xmms2_title:
1852 if (info.xmms2.title) {
1853 free(info.xmms2.title);
1854 info.xmms2.title = 0;
1857 case OBJ_xmms2_genre:
1858 if (info.xmms2.genre) {
1859 free(info.xmms2.genre);
1860 info.xmms2.genre = 0;
1863 case OBJ_xmms2_comment:
1864 if (info.xmms2.comment) {
1865 free(info.xmms2.comment);
1866 info.xmms2.comment = 0;
1869 case OBJ_xmms2_decoder:
1870 if (info.xmms2.decoder) {
1871 free(info.xmms2.decoder);
1875 case OBJ_xmms2_transport:
1876 if (info.xmms2.transport) {
1877 free(info.xmms2.transport);
1882 if (info.xmms2.url) {
1883 free(info.xmms2.url);
1887 case OBJ_xmms2_date:
1888 if (info.xmms2.date) {
1889 free(info.xmms2.date);
1890 info.xmms2.date = 0;
1893 case OBJ_xmms2_status:
1894 if (info.xmms2.status) {
1895 free(info.xmms2.status);
1896 info.xmms2.status = 0;
1899 case OBJ_xmms2_smart:
1900 if (info.xmms2.artist) {
1901 free(info.xmms2.artist);
1902 info.xmms2.artist = 0;
1904 if (info.xmms2.title) {
1905 free(info.xmms2.title);
1906 info.xmms2.title = 0;
1908 if (info.xmms2.url) {
1909 free(info.xmms2.url);
1915 case OBJ_bmpx_title:
1916 case OBJ_bmpx_artist:
1917 case OBJ_bmpx_album:
1918 case OBJ_bmpx_track:
1920 case OBJ_bmpx_bitrate:
1924 free(objs[i].data.s);
1928 free(objs[i].data.execi.cmd);
1929 free(objs[i].data.execi.buffer);
1932 free(objs[i].data.texeci.cmd);
1933 free(objs[i].data.texeci.buffer);
1936 if (info.first_process) {
1937 free_all_processes();
1938 info.first_process = NULL;
1942 if (info.first_process) {
1943 free_all_processes();
1944 info.first_process = NULL;
1949 free(objs[i].data.hddtemp.dev);
1950 free(objs[i].data.hddtemp.addr);
1953 case OBJ_entropy_avail:
1954 case OBJ_entropy_poolsize:
1955 case OBJ_entropy_bar:
1960 //text_objects = NULL;
1961 //text_object_count = 0;
1964 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1969 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1970 *a = mixer_init(buf1);
1971 (void) scan_bar(arg + n, w, h);
1974 (void) scan_bar(arg, w, h);
1979 /* construct_text_object() creates a new text_object */
1980 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
1982 //struct text_object *obj = new_text_object();
1983 struct text_object *obj = new_text_object_internal();
1986 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
1987 #define END ; } } else
1991 obj->type = OBJ_color;
1992 obj->data.l = get_x11_color(s);
1995 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
1996 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
1997 END OBJ(acpiacadapter, 0)
1998 #if defined(__linux__)
2005 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2007 obj->data.cpu_index=1;
2008 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2012 obj->data.cpu_index=atoi(&arg[0]);
2021 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2023 obj->data.cpu_index=1;
2024 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2028 obj->data.cpu_index=atoi(&arg[0]);
2031 END OBJ(voltage_mv, 0)
2037 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2039 obj->data.cpu_index=1;
2040 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2044 obj->data.cpu_index=atoi(&arg[0]);
2047 END OBJ(voltage_v, 0)
2053 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2055 obj->data.cpu_index=1;
2056 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2060 obj->data.cpu_index=atoi(&arg[0]);
2066 #endif /* __linux__ */
2067 END OBJ(freq_dyn, 0);
2068 END OBJ(freq_dyn_g, 0);
2069 END OBJ(acpifan, 0);
2070 END OBJ(battery, 0);
2073 sscanf(arg, "%63s", bat);
2075 strcpy(bat, "BAT0");
2076 obj->data.s = strdup(bat);
2077 #if defined(__linux__)
2078 END OBJ(i8k_version, INFO_I8K)
2079 END OBJ(i8k_bios, INFO_I8K)
2080 END OBJ(i8k_serial, INFO_I8K)
2081 END OBJ(i8k_cpu_temp, INFO_I8K)
2082 END OBJ(i8k_cpu_tempf, INFO_I8K)
2083 END OBJ(i8k_left_fan_status, INFO_I8K)
2084 END OBJ(i8k_right_fan_status, INFO_I8K)
2085 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2086 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2087 END OBJ(i8k_ac_status, INFO_I8K)
2088 END OBJ(i8k_buttons_status, INFO_I8K)
2090 END OBJ(ibm_temps, 0)
2092 CRIT_ERR("ibm_temps: needs an argument");
2094 if (!isdigit(arg[0])
2096 || atoi(&arg[0]) >=8)
2099 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2101 obj->data.sensor = atoi(&arg[0]);
2102 END OBJ(ibm_volume, 0)
2103 END OBJ(ibm_brightness, 0)
2104 END OBJ(pb_battery, 0)
2105 if (arg && strcmp(arg, "status") == 0) {
2106 obj->data.i = PB_BATT_STATUS;
2107 } else if (arg && strcmp(arg, "percent") == 0) {
2108 obj->data.i = PB_BATT_PERCENT;
2109 } else if (arg && strcmp(arg, "time") == 0) {
2110 obj->data.i = PB_BATT_TIME;
2112 ERR("pb_battery: needs one argument: status, percent or time");
2117 #endif /* __linux__ */
2118 END OBJ(buffers, INFO_BUFFERS)
2119 END OBJ(cached, INFO_BUFFERS)
2120 END OBJ(cpu, INFO_CPU)
2122 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2123 obj->data.cpu_index = atoi(&arg[3]);
2125 } else {obj->data.cpu_index = 0; }
2127 obj->data.cpu_index = 0;
2129 END OBJ(cpubar, INFO_CPU)
2131 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2132 obj->data.cpu_index = atoi(&arg[3]);
2135 else {obj->data.cpu_index = 0;}
2136 (void) scan_bar(arg, &obj->a, &obj->b);
2138 (void) scan_bar(arg, &obj->a, &obj->b);
2139 obj->data.cpu_index = 0;
2141 END OBJ(cpugraph, INFO_CPU)
2143 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2144 obj->data.cpu_index = atoi(&arg[3]);
2147 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2149 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2150 obj->data.cpu_index = 0;
2152 END OBJ(diskio, INFO_DISKIO)
2153 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2156 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2160 obj->data.s = scan_font(arg);
2162 OBJ(downspeed, INFO_NET)
2164 obj->data.net = get_net_stat(arg);
2167 CRIT_ERR("downspeed needs argument");
2169 END OBJ(downspeedf, INFO_NET)
2171 obj->data.net = get_net_stat(arg);
2174 CRIT_ERR("downspeedf needs argument");
2176 END OBJ(downspeedgraph, INFO_NET)
2177 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2179 sscanf(arg, "%63s %*i,%*i %*i", buf);
2180 obj->data.net = get_net_stat(buf);
2181 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2182 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2189 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2190 blockstart[blockdepth - 1] = object_count;
2191 obj->data.ifblock.pos = object_count + 2;
2193 ERR("$else: no matching $if_*");
2198 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2200 ERR("$endif: no matching $if_*");
2203 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2206 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2207 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2208 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2209 END OBJ(execibar, 0) unsigned int n;
2210 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2212 ERR("${execibar <interval> command}");
2213 obj->type = OBJ_text;
2214 snprintf(buf, 256, "${%s}", s);
2215 obj->data.s = strdup(buf);
2217 obj->data.execi.cmd = strdup(arg + n);
2219 END OBJ(execigraph, 0) unsigned int n;
2220 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2222 ERR("${execigraph <interval> command}");
2223 obj->type = OBJ_text;
2224 snprintf(buf, 256, "${%s}", s);
2225 obj->data.s = strdup(buf);
2227 obj->data.execi.cmd = strdup(arg + n);
2229 END OBJ(execi, 0) unsigned int n;
2230 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2232 ERR("${execi <interval> command}");
2233 obj->type = OBJ_text;
2234 snprintf(buf, 256, "${%s}", s);
2235 obj->data.s = strdup(buf);
2237 obj->data.execi.cmd = strdup(arg + n);
2238 obj->data.execi.buffer =
2239 (char *) calloc(1, TEXT_BUFFER_SIZE);
2241 END OBJ(texeci, 0) unsigned int n;
2242 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2244 ERR("${texeci <interval> command}");
2245 obj->type = OBJ_text;
2246 snprintf(buf, 256, "${%s}", s);
2247 obj->data.s = strdup(buf);
2249 obj->data.texeci.cmd = strdup(arg + n);
2250 obj->data.texeci.buffer =
2251 (char *) calloc(1, TEXT_BUFFER_SIZE);
2253 obj->data.texeci.p_timed_thread = NULL;
2254 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2256 FILE *fp = popen(arg, "r");
2260 n = fread(buf, 1, 2048, fp);
2263 if (n && buf[n - 1] == '\n')
2268 obj->data.s = strdup(buf);
2270 obj->data.s = strdup("");
2273 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2274 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2276 while (isspace(*arg))
2282 obj->data.fsbar.fs = prepare_fs_stat(arg);
2283 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2286 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2290 obj->data.fsbar.fs = prepare_fs_stat(arg);
2291 END OBJ(fs_free, INFO_FS) if (!arg)
2293 obj->data.fs = prepare_fs_stat(arg);
2294 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2296 obj->data.fs = prepare_fs_stat(arg);
2297 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2299 obj->data.fs = prepare_fs_stat(arg);
2300 END OBJ(fs_size, INFO_FS) if (!arg)
2302 obj->data.fs = prepare_fs_stat(arg);
2303 END OBJ(fs_used, INFO_FS) if (!arg)
2305 obj->data.fs = prepare_fs_stat(arg);
2306 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2307 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2308 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2312 ERR("goto needs arguments");
2313 obj->type = OBJ_text;
2314 obj->data.s = strdup("${goto}");
2318 obj->data.i = atoi(arg);
2323 if (sscanf(arg, "%d %d", &a, &b) != 2)
2324 sscanf(arg, "%d", &b);
2328 obj->data.pair.a = a;
2329 obj->data.pair.b = b;
2331 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2335 ERR("i2c needs arguments");
2336 obj->type = OBJ_text;
2337 //obj->data.s = strdup("${i2c}");
2341 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2342 /* if scanf couldn't read three values, read type and num and use
2344 sscanf(arg, "%63s %d", buf2, &n);
2346 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2347 obj->data.i2c.devtype);
2348 strncpy(obj->data.i2c.type, buf2, 63);
2351 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2352 obj->data.i2c.devtype);
2353 strncpy(obj->data.i2c.type, buf2, 63);
2356 END OBJ(top, INFO_TOP)
2360 ERR("top needs arguments");
2361 obj->type = OBJ_text;
2362 //obj->data.s = strdup("${top}");
2365 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2366 if (strcmp(buf, "name") == 0) {
2367 obj->data.top.type = TOP_NAME;
2368 } else if (strcmp(buf, "cpu") == 0) {
2369 obj->data.top.type = TOP_CPU;
2370 } else if (strcmp(buf, "pid") == 0) {
2371 obj->data.top.type = TOP_PID;
2372 } else if (strcmp(buf, "mem") == 0) {
2373 obj->data.top.type = TOP_MEM;
2375 ERR("invalid arg for top");
2378 if (n < 1 || n > 10) {
2379 CRIT_ERR("invalid arg for top");
2382 obj->data.top.num = n - 1;
2386 ERR("invalid args given for top");
2389 END OBJ(top_mem, INFO_TOP)
2393 ERR("top_mem needs arguments");
2394 obj->type = OBJ_text;
2395 obj->data.s = strdup("${top_mem}");
2398 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2399 if (strcmp(buf, "name") == 0) {
2400 obj->data.top.type = TOP_NAME;
2401 } else if (strcmp(buf, "cpu") == 0) {
2402 obj->data.top.type = TOP_CPU;
2403 } else if (strcmp(buf, "pid") == 0) {
2404 obj->data.top.type = TOP_PID;
2405 } else if (strcmp(buf, "mem") == 0) {
2406 obj->data.top.type = TOP_MEM;
2408 ERR("invalid arg for top");
2411 if (n < 1 || n > 10) {
2412 CRIT_ERR("invalid arg for top");
2415 obj->data.top.num = n - 1;
2419 ERR("invalid args given for top");
2422 END OBJ(addr, INFO_NET)
2424 obj->data.net = get_net_stat(arg);
2427 CRIT_ERR("addr needs argument");
2429 END OBJ(linkstatus, INFO_WIFI)
2431 obj->data.net = get_net_stat(arg);
2434 CRIT_ERR("linkstatus needs argument");
2440 ERR("tail needs arguments");
2441 obj->type = OBJ_text;
2442 obj->data.s = strdup("${tail}");
2445 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2446 if (n1 < 1 || n1 > 30) {
2447 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2451 fp = fopen(buf, "r");
2453 obj->data.tail.logfile =
2454 malloc(TEXT_BUFFER_SIZE);
2455 strcpy(obj->data.tail.logfile, buf);
2456 obj->data.tail.wantedlines = n1 - 1;
2457 obj->data.tail.interval =
2458 update_interval * 2;
2462 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2465 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2466 if (n1 < 1 || n1 > 30) {
2468 ("invalid arg for tail, number of lines must be between 1 and 30");
2470 } else if (n2 < 1 || n2 < update_interval) {
2472 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2476 fp = fopen(buf, "r");
2478 obj->data.tail.logfile =
2479 malloc(TEXT_BUFFER_SIZE);
2480 strcpy(obj->data.tail.logfile, buf);
2481 obj->data.tail.wantedlines = n1 - 1;
2482 obj->data.tail.interval = n2;
2486 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2492 ERR("invalid args given for tail");
2495 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
2500 ERR("head needs arguments");
2501 obj->type = OBJ_text;
2502 obj->data.s = strdup("${head}");
2505 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2506 if (n1 < 1 || n1 > 30) {
2507 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2511 fp = fopen(buf, "r");
2513 obj->data.tail.logfile =
2514 malloc(TEXT_BUFFER_SIZE);
2515 strcpy(obj->data.tail.logfile, buf);
2516 obj->data.tail.wantedlines = n1 - 1;
2517 obj->data.tail.interval =
2518 update_interval * 2;
2522 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2525 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2526 if (n1 < 1 || n1 > 30) {
2528 ("invalid arg for head, number of lines must be between 1 and 30");
2530 } else if (n2 < 1 || n2 < update_interval) {
2532 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2536 fp = fopen(buf, "r");
2538 obj->data.tail.logfile =
2539 malloc(TEXT_BUFFER_SIZE);
2540 strcpy(obj->data.tail.logfile, buf);
2541 obj->data.tail.wantedlines = n1 - 1;
2542 obj->data.tail.interval = n2;
2546 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2552 ERR("invalid args given for head");
2555 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
2556 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2558 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2559 if (r >= 3 && (c < 1 || c > 3))
2561 if (r >= 2 && (b < 1 || b > 3))
2563 if (r >= 1 && (a < 1 || a > 3))
2566 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2567 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2568 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2569 END OBJ(if_existing, 0)
2570 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2571 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2574 ERR("if_existing needs an argument");
2575 obj->data.ifblock.s = 0;
2577 obj->data.ifblock.s = strdup(arg);
2578 blockstart[blockdepth] = object_count;
2579 obj->data.ifblock.pos = object_count + 2;
2581 END OBJ(if_mounted, 0)
2582 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2583 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2586 ERR("if_mounted needs an argument");
2587 obj->data.ifblock.s = 0;
2589 obj->data.ifblock.s = strdup(arg);
2590 blockstart[blockdepth] = object_count;
2591 obj->data.ifblock.pos = object_count + 2;
2593 END OBJ(if_running, 0)
2594 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2595 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2599 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2600 obj->data.ifblock.s = strdup(buf);
2602 ERR("if_running needs an argument");
2603 obj->data.ifblock.s = 0;
2605 blockstart[blockdepth] = object_count;
2606 obj->data.ifblock.pos = object_count + 2;
2610 END OBJ(mails, INFO_MAIL)
2611 END OBJ(mem, INFO_MEM)
2612 END OBJ(memmax, INFO_MEM)
2613 END OBJ(memperc, INFO_MEM)
2614 END OBJ(membar, INFO_MEM)
2615 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2616 END OBJ(memgraph, INFO_MEM)
2617 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2618 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2619 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2620 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2621 END OBJ(mixerbar, INFO_MIXER)
2622 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2623 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2624 END OBJ(mixerlbar, INFO_MIXER)
2625 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2626 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2627 END OBJ(mixerrbar, INFO_MIXER)
2628 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2629 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2631 OBJ(new_mails, INFO_MAIL)
2632 END OBJ(nodename, 0)
2633 END OBJ(processes, INFO_PROCS)
2634 END OBJ(running_processes, INFO_RUN_PROCS)
2635 END OBJ(shadecolor, 0)
2637 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2639 END OBJ(outlinecolor, 0)
2641 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2643 END OBJ(stippled_hr, 0)
2645 int a = stippled_borders, b = 1;
2647 if (sscanf(arg, "%d %d", &a, &b) != 2)
2648 sscanf(arg, "%d", &b);
2652 obj->data.pair.a = a;
2653 obj->data.pair.b = b;
2655 END OBJ(swap, INFO_MEM)
2656 END OBJ(swapmax, INFO_MEM)
2657 END OBJ(swapperc, INFO_MEM)
2658 END OBJ(swapbar, INFO_MEM)
2659 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2660 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2662 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2663 obj->data.i2c.devtype);
2664 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2666 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2667 obj->data.i2c.devtype);
2668 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2669 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2671 char buf1[256], buf2[256], *fmt, *tz;
2674 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2683 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2684 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2686 END OBJ(iconv_start, 0)
2687 if (iconv_converting) {
2688 CRIT_ERR("You must stop your last iconv conversion before starting another");
2691 char iconv_from[CODEPAGE_LENGTH];
2692 char iconv_to[CODEPAGE_LENGTH];
2693 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2694 CRIT_ERR("Invalid arguments for iconv_start");
2697 new_iconv = iconv_open(iconv_to, iconv_from);
2698 if (new_iconv == (iconv_t)(-1)) {
2699 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2701 obj->a = register_iconv(&new_iconv);
2702 iconv_converting = 1;
2706 CRIT_ERR("Iconv requires arguments");
2708 END OBJ(iconv_stop, 0)
2709 iconv_converting = 0;
2712 END OBJ(totaldown, INFO_NET)
2714 obj->data.net = get_net_stat(arg);
2717 CRIT_ERR("totaldown needs argument");
2719 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2721 obj->data.net = get_net_stat(arg);
2724 CRIT_ERR("totalup needs argument");
2727 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2728 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2729 END OBJ(upspeed, INFO_NET)
2731 obj->data.net = get_net_stat(arg);
2734 CRIT_ERR("upspeed needs argument");
2736 END OBJ(upspeedf, INFO_NET)
2738 obj->data.net = get_net_stat(arg);
2741 CRIT_ERR("upspeedf needs argument");
2744 END OBJ(upspeedgraph, INFO_NET)
2745 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2747 sscanf(arg, "%63s %*i,%*i %*i", buf);
2748 obj->data.net = get_net_stat(buf);
2749 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2750 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2755 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2756 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2757 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2758 OBJ(apm_adapter, 0) END
2759 OBJ(apm_battery_life, 0) END
2760 OBJ(apm_battery_time, 0) END
2761 #endif /* __FreeBSD__ */
2765 obj->data.mail = parse_mail_args(IMAP, arg);
2766 obj->global_mode = 0;
2768 obj->global_mode = 1;
2771 OBJ(imap_messages, 0)
2774 obj->data.mail = parse_mail_args(IMAP, arg);
2775 obj->global_mode = 0;
2777 obj->global_mode = 1;
2783 obj->data.mail = parse_mail_args(POP3, arg);
2784 obj->global_mode = 0;
2786 obj->global_mode = 1;
2792 obj->data.mail = parse_mail_args(POP3, arg);
2793 obj->global_mode = 0;
2795 obj->global_mode = 1;
2799 OBJ(mpd_artist, INFO_MPD)
2800 END OBJ(mpd_title, INFO_MPD)
2801 END OBJ(mpd_random, INFO_MPD)
2802 END OBJ(mpd_repeat, INFO_MPD)
2803 END OBJ(mpd_elapsed, INFO_MPD)
2804 END OBJ(mpd_length, INFO_MPD)
2805 END OBJ(mpd_track, INFO_MPD)
2806 END OBJ(mpd_name, INFO_MPD)
2807 END OBJ(mpd_file, INFO_MPD)
2808 END OBJ(mpd_percent, INFO_MPD)
2809 END OBJ(mpd_album, INFO_MPD)
2810 END OBJ(mpd_vol, INFO_MPD)
2811 END OBJ(mpd_bitrate, INFO_MPD)
2812 END OBJ(mpd_status, INFO_MPD)
2813 END OBJ(mpd_bar, INFO_MPD)
2814 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2815 END OBJ(mpd_smart, INFO_MPD) END
2818 OBJ(xmms2_artist, INFO_XMMS2)
2819 END OBJ(xmms2_album, INFO_XMMS2)
2820 END OBJ(xmms2_title, INFO_XMMS2)
2821 END OBJ(xmms2_genre, INFO_XMMS2)
2822 END OBJ(xmms2_comment, INFO_XMMS2)
2823 END OBJ(xmms2_decoder, INFO_XMMS2)
2824 END OBJ(xmms2_transport, INFO_XMMS2)
2825 END OBJ(xmms2_url, INFO_XMMS2)
2826 END OBJ(xmms2_tracknr, INFO_XMMS2)
2827 END OBJ(xmms2_bitrate, INFO_XMMS2)
2828 END OBJ(xmms2_date, INFO_XMMS2)
2829 END OBJ(xmms2_id, INFO_XMMS2)
2830 END OBJ(xmms2_duration, INFO_XMMS2)
2831 END OBJ(xmms2_elapsed, INFO_XMMS2)
2832 END OBJ(xmms2_size, INFO_XMMS2)
2833 END OBJ(xmms2_status, INFO_XMMS2)
2834 END OBJ(xmms2_percent, INFO_XMMS2)
2835 END OBJ(xmms2_bar, INFO_XMMS2)
2836 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2837 END OBJ(xmms2_smart, INFO_XMMS2)
2841 OBJ(audacious_status, INFO_AUDACIOUS) END
2842 OBJ(audacious_title, INFO_AUDACIOUS)
2846 sscanf (arg, "%d", &info.audacious.max_title_len);
2847 if (info.audacious.max_title_len > 0)
2848 info.audacious.max_title_len++;
2850 CRIT_ERR ("audacious_title: invalid length argument");
2854 OBJ(audacious_length, INFO_AUDACIOUS) END
2855 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
2856 OBJ(audacious_position, INFO_AUDACIOUS) END
2857 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
2858 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
2859 OBJ(audacious_frequency, INFO_AUDACIOUS) END
2860 OBJ(audacious_channels, INFO_AUDACIOUS) END
2861 OBJ(audacious_filename, INFO_AUDACIOUS) END
2862 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
2863 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
2864 OBJ(audacious_bar, INFO_AUDACIOUS)
2865 (void) scan_bar(arg, &obj->a, &obj->b);
2869 OBJ(bmpx_title, INFO_BMPX)
2870 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2872 OBJ(bmpx_artist, INFO_BMPX)
2873 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2875 OBJ(bmpx_album, INFO_BMPX)
2876 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2878 OBJ(bmpx_track, INFO_BMPX)
2879 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2881 OBJ(bmpx_uri, INFO_BMPX)
2882 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2884 OBJ(bmpx_bitrate, INFO_BMPX)
2885 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2890 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
2891 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2892 ERR("hddtemp needs arguments");
2893 obj->type = OBJ_text;
2894 obj->data.s = strdup("${hddtemp}");
2899 #ifdef TCP_PORT_MONITOR
2900 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2901 int argc, port_begin, port_end, item, connection_index;
2903 memset(itembuf,0,sizeof(itembuf));
2905 /* massive argument checking */
2907 CRIT_ERR("tcp_portmon: needs arguments");
2909 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
2910 if ( (argc != 3) && (argc != 4) )
2912 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
2914 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
2916 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
2918 if ( port_begin > port_end )
2920 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
2922 if ( strncmp(itembuf,"count",31) == 0 )
2924 else if ( strncmp(itembuf,"rip",31) == 0 )
2926 else if ( strncmp(itembuf,"rhost",31) == 0 )
2928 else if ( strncmp(itembuf,"rport",31) == 0 )
2930 else if ( strncmp(itembuf,"rservice",31) == 0 )
2932 else if ( strncmp(itembuf,"lip",31) == 0 )
2934 else if ( strncmp(itembuf,"lhost",31) == 0 )
2936 else if ( strncmp(itembuf,"lport",31) == 0 )
2938 else if ( strncmp(itembuf,"lservice",31) == 0 )
2942 CRIT_ERR("tcp_portmon: invalid item specified");
2944 if ( (argc==3) && (item!=COUNT) )
2946 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
2948 if ( (argc==4) && (connection_index<0) )
2950 CRIT_ERR("tcp_portmon: connection index must be non-negative");
2952 /* ok, args looks good. save the text object data */
2953 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
2954 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
2955 obj->data.tcp_port_monitor.item = item;
2956 obj->data.tcp_port_monitor.connection_index = connection_index;
2958 /* if the port monitor collection hasn't been created, we must create it */
2959 if ( !info.p_tcp_port_monitor_collection )
2961 info.p_tcp_port_monitor_collection =
2962 create_tcp_port_monitor_collection( &tcp_port_monitor_collection_args );
2963 if ( !info.p_tcp_port_monitor_collection )
2965 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
2969 /* if a port monitor for this port does not exist, create one and add it to the collection */
2970 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
2972 tcp_port_monitor_t * p_monitor =
2973 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
2976 CRIT_ERR("tcp_portmon: unable to create port monitor");
2978 /* add the newly created monitor to the collection */
2979 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
2982 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
2987 OBJ(entropy_avail, INFO_ENTROPY) END
2988 OBJ(entropy_poolsize, INFO_ENTROPY) END
2989 OBJ(entropy_bar, INFO_ENTROPY)
2990 (void) scan_bar(arg, &obj->a, &obj->b);
2995 ERR("unknown variable %s", s);
2996 obj->type = OBJ_text;
2997 snprintf(buf, 256, "${%s}", s);
2998 obj->data.s = strdup(buf);
3005 static struct text_object *create_plain_text(const char *s)
3007 struct text_object *obj;
3009 if (s == NULL || *s == '\0') {
3013 obj = new_text_object_internal();
3015 obj->type = OBJ_text;
3016 obj->data.s = strdup(s);
3020 static struct text_object_list *extract_variable_text_internal(const char *p)
3022 struct text_object_list *retval;
3023 struct text_object *obj;
3026 retval = malloc(sizeof(struct text_object_list));
3027 memset(retval, 0, sizeof(struct text_object_list));
3028 retval->text_object_count = 0;
3030 long line = text_lines;
3038 obj = create_plain_text(s);
3040 // allocate memory for the object
3041 retval->text_objects = realloc(retval->text_objects,
3042 sizeof(struct text_object) * (retval->text_object_count+1));
3043 // assign the new object to the end of the list.
3044 memcpy(&retval->text_objects[retval->text_object_count++],
3045 obj, sizeof(struct text_object));
3057 /* variable is either $foo or ${foo} */
3061 while (*p && *p != '}')
3067 while (*p && (isalnum((int) *p)
3072 /* copy variable to buffer */
3073 len = (p - s > 255) ? 255 : (p - s);
3074 strncpy(buf, s, len);
3083 /* if variable wasn't found from environment, use some special */
3089 if (strchr(buf, ' ')) {
3090 arg = strchr(buf, ' ');
3093 while (isspace((int) *arg))
3099 /* lowercase variable name */
3106 // create new object
3107 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3109 // allocate memory for the object
3110 retval->text_objects = realloc(retval->text_objects,
3111 sizeof(struct text_object) * (retval->text_object_count+1));
3112 // assign the new object to the end of the list.
3113 memcpy(&retval->text_objects[retval->text_object_count++],
3114 obj, sizeof(struct text_object));
3120 obj = create_plain_text("$");
3122 // allocate memory for the object
3123 retval->text_objects = realloc(retval->text_objects,
3124 sizeof(struct text_object) * (retval->text_object_count+1));
3125 // assign the new object to the end of the list.
3126 memcpy(&retval->text_objects[retval->text_object_count++],
3127 obj, sizeof(struct text_object));
3134 obj = create_plain_text(s);
3136 // allocate memory for the object
3137 retval->text_objects = realloc(retval->text_objects,
3138 sizeof(struct text_object) * (retval->text_object_count+1));
3139 // assign the new object to the end of the list.
3140 memcpy(&retval->text_objects[retval->text_object_count++],
3141 obj, sizeof(struct text_object));
3146 ERR("one or more $endif's are missing");
3152 static void extract_variable_text(const char *p)
3154 struct text_object_list *list;
3156 free_text_objects(text_object_count, text_objects);
3157 text_object_count = 0;
3158 text_objects = NULL;
3161 list = extract_variable_text_internal(p);
3162 text_objects = list->text_objects;
3163 text_object_count = list->text_object_count;
3170 void parse_conky_vars(char * text, char * p, struct information *cur) {
3171 struct text_object_list *object_list = extract_variable_text_internal(text);
3172 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3176 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3181 char buff_in[P_MAX_SIZE] = {0};
3182 iconv_converting = 0;
3185 for (i = 0; i < object_count; i++) {
3186 struct text_object *obj = &objs[i];
3188 #define OBJ(a) break; case OBJ_##a:
3190 switch (obj->type) {
3193 ERR("not implemented obj type %d",
3197 /* does anyone have decimals in acpi temperature? */
3199 snprintf(p, p_max_size, "%d", (int)
3200 get_acpi_temperature(obj->
3204 snprintf(p, 5, "%d ", (int)
3205 get_acpi_temperature(obj->
3210 /* does anyone have decimals in acpi temperature? */
3212 snprintf(p, p_max_size, "%d", (int)
3213 ((get_acpi_temperature(obj->
3215 i)+ 40) * 9.0 / 5 - 40));
3217 snprintf(p, 5, "%d ", (int)
3218 ((get_acpi_temperature(obj->
3220 i)+ 40) * 9.0 / 5 - 40));
3224 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3229 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3232 #if defined(__linux__)
3235 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3240 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3243 #endif /* __linux__ */
3247 get_freq_dynamic(p, 6, "%.0f ", 1 );
3249 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3254 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3256 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3260 get_adt746x_cpu(p, p_max_size);
3263 get_adt746x_fan(p, p_max_size);
3266 get_acpi_fan(p, p_max_size);
3268 OBJ(acpiacadapter) {
3269 get_acpi_ac_adapter(p, p_max_size);
3272 get_battery_stuff(p, p_max_size, obj->data.s);
3275 human_readable(cur->buffers * 1024, p, 255);
3278 human_readable(cur->cached * 1024, p, 255);
3281 if (obj->data.cpu_index > info.cpu_count) {
3282 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3283 CRIT_ERR("attempting to use more CPUs then you have!");
3286 snprintf(p, p_max_size, "%*d", pad_percents,
3287 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3290 snprintf(p, 4, "%*d ",
3292 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3298 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3301 new_graph(p, obj->a,
3302 obj->b, obj->c, obj->d,
3303 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3307 new_fg(p, obj->data.l);
3309 #if defined(__linux__)
3311 snprintf(p, p_max_size, "%s", i8k.version);
3314 snprintf(p, p_max_size, "%s", i8k.bios);
3317 snprintf(p, p_max_size, "%s", i8k.serial);
3320 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3322 OBJ(i8k_cpu_tempf) {
3324 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3325 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3327 OBJ(i8k_left_fan_status) {
3328 int left_fan_status;
3329 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3330 if(left_fan_status == 0) {
3331 snprintf(p, p_max_size,"off");
3332 } if(left_fan_status == 1) {
3333 snprintf(p, p_max_size, "low");
3334 } if(left_fan_status == 2) {
3335 snprintf(p, p_max_size, "high");
3339 OBJ(i8k_right_fan_status) {
3340 int right_fan_status;
3341 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3342 if(right_fan_status == 0) {
3343 snprintf(p, p_max_size,"off");
3344 } if(right_fan_status == 1) {
3345 snprintf(p, p_max_size, "low");
3346 } if(right_fan_status == 2) {
3347 snprintf(p, p_max_size, "high");
3350 OBJ(i8k_left_fan_rpm) {
3351 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3353 OBJ(i8k_right_fan_rpm) {
3354 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3356 OBJ(i8k_ac_status) {
3358 sscanf(i8k.ac_status, "%d", &ac_status);
3359 if(ac_status == -1) {
3360 snprintf(p, p_max_size,"disabled (read i8k docs)");
3361 } if(ac_status == 0) {
3362 snprintf(p, p_max_size, "off");
3363 } if(ac_status == 1) {
3364 snprintf(p, p_max_size, "on");
3367 OBJ(i8k_buttons_status) {
3368 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3372 get_ibm_acpi_fan(p, p_max_size);
3375 get_ibm_acpi_temps();
3376 snprintf(p, p_max_size, "%d",
3377 ibm_acpi.temps[obj->data.sensor]);
3380 get_ibm_acpi_volume(p, p_max_size);
3382 OBJ(ibm_brightness) {
3383 get_ibm_acpi_brightness(p, p_max_size);
3386 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3388 #endif /* __linux__ */
3392 new_font(p, obj->data.s);
3397 if (diskio_value > 1024*1024) {
3398 snprintf(p, p_max_size, "%.1fGiB",
3399 (double)diskio_value/1024/1024);
3400 } else if (diskio_value > 1024) {
3401 snprintf(p, p_max_size, "%.1fMiB",
3402 (double)diskio_value/1024);
3403 } else if (diskio_value > 0) {
3404 snprintf(p, p_max_size, "%dKiB", diskio_value);
3406 snprintf(p, p_max_size, "%dB", diskio_value);
3409 if (diskio_value > 1024*1024) {
3410 snprintf(p, 6, "%.1fGiB ",
3411 (double)diskio_value/1024/1024);
3412 } else if (diskio_value > 1024) {
3413 snprintf(p, 6, "%.1fMiB ",
3414 (double)diskio_value/1024);
3415 } else if (diskio_value > 0) {
3416 snprintf(p, 6, "%dKiB ", diskio_value);
3418 snprintf(p, 6, "%dB ", diskio_value);
3423 new_graph(p, obj->a,
3424 obj->b, obj->c, obj->d,
3425 diskio_value, obj->e, 1);
3430 snprintf(p, p_max_size, "%d",
3431 (int) (obj->data.net->
3435 snprintf(p, 6, "%d ",
3436 (int) (obj->data.net->
3442 snprintf(p, p_max_size, "%.1f",
3444 recv_speed / 1024.0);
3446 snprintf(p, 8, "%.1f ",
3448 recv_speed / 1024.0);
3450 OBJ(downspeedgraph) {
3451 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
3452 obj->data.net->recv_speed = 0.01;
3453 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3454 (obj->data.net->recv_speed /
3455 1024.0), obj->e, 1);
3459 i = obj->data.ifblock.pos - 1;
3469 snprintf(p, p_max_size, "%u.%u.%u.%u",
3470 obj->data.net->addr.
3472 obj->data.net->addr.
3474 obj->data.net->addr.
3476 obj->data.net->addr.
3482 snprintf(p, p_max_size, "%d",
3483 obj->data.net->linkstatus);
3486 snprintf(p, 5, "%4d ",
3487 obj->data.net->linkstatus);
3490 #if defined(IMLIB2) && defined(X11)
3495 Imlib_Image image, buffer;
3496 image = imlib_load_image(obj->data.s);
3497 imlib_context_set_image(image);
3500 w = imlib_image_get_width();
3501 h = imlib_image_get_height();
3502 buffer = imlib_create_image(w, h);
3503 imlib_context_set_display(display);
3504 imlib_context_set_drawable(window.drawable);
3505 imlib_context_set_colormap(DefaultColormap(display, screen));
3506 imlib_context_set_visual(DefaultVisual(display, screen));
3507 imlib_context_set_image(buffer);
3508 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3509 imlib_render_image_on_drawable(text_start_x, text_start_y);
3511 imlib_context_set_image(image);
3518 FILE *fp = popen(obj->data.s, "r");
3519 int length = fread(p, 1, p_max_size, fp);
3522 /*output[length] = '\0';
3523 if (length > 0 && output[length - 1] == '\n') {
3524 output[length - 1] = '\0';
3527 if (length > 0 && p[length - 1] == '\n') {
3528 p[length - 1] = '\0';
3531 //parse_conky_vars(output, p, cur);
3535 FILE *fp = popen(obj->data.s, "r");
3536 int n2 = fread(p, 1, p_max_size, fp);
3540 if (n2 && p[n2 - 1] == '\n')
3549 if (sscanf(p, "%lf", &barnum) == 0) {
3550 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3552 if (barnum > 100 || barnum < 0) {
3553 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3555 barnum = barnum / 100.0;
3556 new_bar(p, 0, 4, (int) (barnum * 255.0));
3562 FILE *fp = popen(obj->data.s, "r");
3563 int n2 = fread(p, 1, p_max_size, fp);
3567 if (n2 && p[n2 - 1] == '\n')
3576 if (sscanf(p, "%lf", &barnum) == 0) {
3577 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3579 if (barnum > 100 || barnum < 0) {
3580 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3582 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3587 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3588 new_bar(p, 0, 4, (int) obj->f);
3591 FILE *fp = popen(obj->data.execi.cmd, "r");
3592 int n2 = fread(p, 1, p_max_size, fp);
3595 if (n2 && p[n2 - 1] == '\n')
3604 if (sscanf(p, "%f", &barnum) == 0) {
3605 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3607 if (barnum > 100 || barnum < 0) {
3608 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3610 obj->f = 255 * barnum / 100.0;
3611 new_bar(p, 0, 4, (int) obj->f);
3613 obj->data.execi.last_update =
3614 current_update_time;
3618 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3619 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3622 FILE *fp = popen(obj->data.execi.cmd, "r");
3623 int n2 = fread(p, 1, p_max_size, fp);
3626 if (n2 && p[n2 - 1] == '\n')
3635 if (sscanf(p, "%f", &barnum) == 0) {
3636 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3638 if (barnum > 100 || barnum < 0) {
3639 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3642 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3644 obj->data.execi.last_update = current_update_time;
3650 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3651 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3653 char *output = obj->data.execi.buffer;
3654 FILE *fp = popen(obj->data.execi.cmd, "r");
3655 //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
3656 int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
3659 output[length] = '\0';
3660 if (length > 0 && output[length - 1] == '\n') {
3661 output[length - 1] = '\0';
3663 obj->data.execi.last_update = current_update_time;
3664 snprintf(p, p_max_size, "%s", output);
3666 //parse_conky_vars(output, p, cur);
3669 if (!obj->data.texeci.p_timed_thread)
3671 obj->data.texeci.p_timed_thread=
3672 timed_thread_create ((void*)threaded_exec, (void*) obj,
3673 obj->data.texeci.interval * 1000000);
3674 if (!obj->data.texeci.p_timed_thread)
3675 ERR("Error starting texeci thread");
3676 timed_thread_register (obj->data.texeci.p_timed_thread,
3677 &obj->data.texeci.p_timed_thread);
3679 timed_thread_lock (obj->data.texeci.p_timed_thread);
3680 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
3681 timed_thread_unlock (obj->data.texeci.p_timed_thread);
3683 #endif /* HAVE_POPEN */
3685 if (obj->global_mode && info.mail) { // this means we use info
3686 if (!info.mail->p_timed_thread)
3688 info.mail->p_timed_thread =
3689 timed_thread_create ((void*)imap_thread,
3691 info.mail->interval * 1000000);
3692 if (!info.mail->p_timed_thread)
3693 ERR("Error starting imap thread");
3694 timed_thread_register (info.mail->p_timed_thread,
3695 &info.mail->p_timed_thread);
3697 timed_thread_lock (info.mail->p_timed_thread);
3698 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3699 timed_thread_unlock (info.mail->p_timed_thread);
3700 } else if (obj->data.mail) { // this means we use obj
3701 if (!obj->data.mail->p_timed_thread)
3703 obj->data.mail->p_timed_thread =
3704 timed_thread_create ((void*)imap_thread,
3705 (void*)obj->data.mail,
3706 obj->data.mail->interval * 1000000);
3707 if (!obj->data.mail->p_timed_thread)
3708 ERR("Error starting imap thread");
3709 timed_thread_register (obj->data.mail->p_timed_thread,
3710 &obj->data.mail->p_timed_thread);
3712 timed_thread_lock (obj->data.mail->p_timed_thread);
3713 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3714 timed_thread_unlock (obj->data.mail->p_timed_thread);
3715 } else if (!obj->a) { // something is wrong, warn once then stop
3716 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3720 OBJ(imap_messages) {
3721 if (obj->global_mode && info.mail) { // this means we use info
3722 if (!info.mail->p_timed_thread)
3724 info.mail->p_timed_thread =
3725 timed_thread_create ((void*)imap_thread,
3727 info.mail->interval * 1000000);
3728 if (!info.mail->p_timed_thread)
3729 ERR("Error starting imap thread");
3730 timed_thread_register (info.mail->p_timed_thread,
3731 &info.mail->p_timed_thread);
3733 timed_thread_lock (info.mail->p_timed_thread);
3734 snprintf(p, p_max_size, "%lu", info.mail->messages);
3735 timed_thread_unlock (info.mail->p_timed_thread);
3736 } else if (obj->data.mail) { // this means we use obj
3737 if (!obj->data.mail->p_timed_thread)
3739 obj->data.mail->p_timed_thread =
3740 timed_thread_create ((void*)imap_thread,
3741 (void*)obj->data.mail,
3742 obj->data.mail->interval * 1000000);
3743 if (!obj->data.mail->p_timed_thread)
3744 ERR("Error starting imap thread");
3745 timed_thread_register (obj->data.mail->p_timed_thread,
3746 &obj->data.mail->p_timed_thread);
3748 timed_thread_lock (obj->data.mail->p_timed_thread);
3749 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
3750 timed_thread_lock (obj->data.mail->p_timed_thread);
3751 } else if (!obj->a) { // something is wrong, warn once then stop
3752 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3757 if (obj->global_mode && info.mail) { // this means we use info
3758 if (!info.mail->p_timed_thread)
3760 info.mail->p_timed_thread =
3761 timed_thread_create ((void*)pop3_thread,
3763 info.mail->interval * 1000000);
3764 if (!info.mail->p_timed_thread)
3765 ERR("Error starting pop3 thread");
3766 timed_thread_register (info.mail->p_timed_thread,
3767 &info.mail->p_timed_thread);
3769 timed_thread_lock (info.mail->p_timed_thread);
3770 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3771 timed_thread_unlock (info.mail->p_timed_thread);
3772 } else if (obj->data.mail) { // this means we use obj
3773 if (!obj->data.mail->p_timed_thread)
3775 obj->data.mail->p_timed_thread =
3776 timed_thread_create ((void*)pop3_thread,
3778 obj->data.mail->interval * 1000000);
3779 if (!obj->data.mail->p_timed_thread)
3780 ERR("Error starting pop3 thread");
3781 timed_thread_register (obj->data.mail->p_timed_thread,
3782 &obj->data.mail->p_timed_thread);
3784 timed_thread_lock (obj->data.mail->p_timed_thread);
3785 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3786 timed_thread_unlock (obj->data.mail->p_timed_thread);
3787 } else if (!obj->a) { // something is wrong, warn once then stop
3788 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
3793 if (obj->global_mode && info.mail) { // this means we use info
3794 if (!info.mail->p_timed_thread)
3796 info.mail->p_timed_thread =
3797 timed_thread_create ((void*)pop3_thread,
3799 info.mail->interval * 1000000);
3800 if (!info.mail->p_timed_thread)
3801 ERR("Error starting pop3 thread");
3802 timed_thread_register (info.mail->p_timed_thread,
3803 &info.mail->p_timed_thread);
3805 timed_thread_lock (info.mail->p_timed_thread);
3806 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
3807 timed_thread_unlock (info.mail->p_timed_thread);
3808 } else if (obj->data.mail) { // this means we use obj
3809 if (!obj->data.mail->p_timed_thread)
3811 obj->data.mail->p_timed_thread =
3812 timed_thread_create ((void*)pop3_thread,
3813 (void*)obj->data.mail,
3814 obj->data.mail->interval * 1000000);
3815 if (!obj->data.mail->p_timed_thread)
3816 ERR("Error starting pop3 thread");
3817 timed_thread_register (obj->data.mail->p_timed_thread,
3818 &obj->data.mail->p_timed_thread);
3820 timed_thread_lock (obj->data.mail->p_timed_thread);
3821 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
3822 timed_thread_unlock (obj->data.mail->p_timed_thread);
3823 } else if (!obj->a) { // something is wrong, warn once then stop
3824 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
3829 if (obj->data.fs != NULL) {
3830 if (obj->data.fs->size == 0)
3849 if (obj->data.fs != NULL)
3850 human_readable(obj->data.fs->avail,
3854 if (obj->data.fs != NULL) {
3855 if (obj->data.fs->size)
3856 snprintf(p, p_max_size, "%*d",
3865 snprintf(p, p_max_size, "0");
3869 if (obj->data.fs != NULL)
3870 human_readable(obj->data.fs->size,
3874 if (obj->data.fs != NULL)
3875 human_readable(obj->data.fs->size -
3876 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
3880 if (obj->data.fs != NULL) {
3881 if (obj->data.fs->size == 0)
3899 if (obj->data.fs != NULL) {
3900 if (obj->data.fs->size)
3901 snprintf(p, 4, "%d",
3911 snprintf(p, p_max_size, "0");
3915 float *v = info.loadavg;
3917 if (obj->data.loadavg[2])
3918 snprintf(p, p_max_size, "%.2f %.2f %.2f",
3919 v[obj->data.loadavg[0] -
3921 v[obj->data.loadavg[1] -
3923 v[obj->data.loadavg[2] -
3925 else if (obj->data.loadavg[1])
3926 snprintf(p, p_max_size, "%.2f %.2f",
3927 v[obj->data.loadavg[0] -
3929 v[obj->data.loadavg[1] -
3931 else if (obj->data.loadavg[0])
3932 snprintf(p, p_max_size, "%.2f",
3933 v[obj->data.loadavg[0] -
3937 new_goto(p, obj->data.i);
3940 new_tab(p, obj->data.pair.a, obj->data.pair.b);
3943 new_hr(p, obj->data.i);
3950 temp = get_hddtemp_info(obj->data.hddtemp.dev,
3951 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
3953 snprintf(p, p_max_size, "N/A");
3954 } else if (unit == '*') {
3955 snprintf(p, p_max_size, "%s", temp);
3957 snprintf(p, p_max_size, "%s°%c", temp, unit);
3962 new_offset(p, obj->data.i);
3965 new_voffset(p, obj->data.i);
3970 r = get_i2c_info(&obj->data.i2c.fd,
3972 obj->data.i2c.devtype,
3973 obj->data.i2c.type);
3975 if (r >= 100.0 || r == 0)
3976 snprintf(p, p_max_size, "%d", (int) r);
3978 snprintf(p, p_max_size, "%.1f", r);
3981 new_alignr(p, obj->data.i);
3984 new_alignc(p, obj->data.i);
3988 if ((obj->data.ifblock.s)
3989 && (stat(obj->data.ifblock.s, &tmp) ==
3991 i = obj->data.ifblock.pos;
3998 if ((obj->data.ifblock.s)
3999 && (!check_mount(obj->data.ifblock.s))) {
4000 i = obj->data.ifblock.pos;
4007 if ((obj->data.ifblock.s)
4008 && system(obj->data.ifblock.s)) {
4009 i = obj->data.ifblock.pos;
4016 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4019 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4024 human_readable(cur->mem * 1024, p, 255);
4027 human_readable(cur->memmax * 1024, p, 255);
4032 snprintf(p, p_max_size, "%*Lu",
4037 snprintf(p, 4, "%*Lu ",
4044 new_bar(p, obj->data.pair.a,
4046 cur->memmax ? (cur->mem * 255) /
4051 new_graph(p, obj->a,
4052 obj->b, obj->c, obj->d,
4053 cur->memmax ? (cur->mem * 100.0) /
4054 (cur->memmax) : 0.0, 100, 1);
4058 snprintf(p, p_max_size, "%d",
4059 mixer_get_avg(obj->data.l));
4062 snprintf(p, p_max_size, "%d",
4063 mixer_get_left(obj->data.l));
4066 snprintf(p, p_max_size, "%d",
4067 mixer_get_right(obj->data.l));
4070 new_bar(p, obj->data.mixerbar.w,
4071 obj->data.mixerbar.h,
4072 mixer_get_avg(obj->data.mixerbar.
4076 new_bar(p, obj->data.mixerbar.w,
4077 obj->data.mixerbar.h,
4078 mixer_get_left(obj->data.mixerbar.
4082 new_bar(p, obj->data.mixerbar.w,
4083 obj->data.mixerbar.h,
4084 mixer_get_right(obj->data.mixerbar.
4090 snprintf(p, p_max_size, "%d", cur->mail_count);
4093 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4097 snprintf(p, p_max_size, "%s",
4098 cur->uname_s.nodename);
4101 new_outline(p, obj->data.l);
4105 snprintf(p, p_max_size, "%hu", cur->procs);
4107 snprintf(p, 5, "%hu ",
4110 OBJ(running_processes) {
4112 snprintf(p, p_max_size, "%hu",
4115 snprintf(p, 3, "%hu ",
4119 snprintf(p, p_max_size, "%s", obj->data.s);
4122 new_bg(p, obj->data.l);
4125 new_stippled_hr(p, obj->data.pair.a,
4129 human_readable(cur->swap * 1024, p, 255);
4132 human_readable(cur->swapmax * 1024, p,
4136 if (cur->swapmax == 0) {
4137 strncpy(p, "No swap", 255);
4140 snprintf(p, 255, "%*Lu",
4146 snprintf(p, 4, "%*Lu ",
4154 new_bar(p, obj->data.pair.a,
4156 cur->swapmax ? (cur->swap * 255) /
4157 (cur->swapmax) : 0);
4160 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4163 time_t t = time(NULL);
4164 struct tm *tm = localtime(&t);
4165 setlocale(LC_TIME, "");
4166 strftime(p, p_max_size, obj->data.s, tm);
4169 time_t t = time(NULL);
4170 struct tm *tm = gmtime(&t);
4171 strftime(p, p_max_size, obj->data.s, tm);
4175 if (obj->data.tztime.tz) {
4176 oldTZ = getenv("TZ");
4177 setenv("TZ", obj->data.tztime.tz, 1);
4180 time_t t = time(NULL);
4181 struct tm *tm = localtime(&t);
4182 setlocale(LC_TIME, "");
4183 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4185 setenv("TZ", oldTZ, 1);
4190 // Needless to free oldTZ since getenv gives ptr to static data
4193 human_readable(obj->data.net->recv, p,
4197 human_readable(obj->data.net->trans, p,
4201 snprintf(p, p_max_size, "%d", total_updates);
4205 snprintf(p, p_max_size, "%d",
4206 (int) (obj->data.net->
4210 snprintf(p, 5, "%d ",
4211 (int) (obj->data.net->
4217 snprintf(p, p_max_size, "%.1f",
4219 trans_speed / 1024.0);
4221 snprintf(p, 8, "%.1f ",
4223 trans_speed / 1024.0);
4226 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
4227 obj->data.net->trans_speed = 0.01;
4228 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4229 (obj->data.net->trans_speed /
4230 1024.0), obj->e, 1);
4233 format_seconds_short(p, p_max_size,
4237 format_seconds(p, p_max_size, (int) cur->uptime);
4240 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
4242 snprintf(p, p_max_size, "%s", get_apm_adapter());
4244 OBJ(apm_battery_life) {
4246 msg = get_apm_battery_life();
4247 snprintf(p, p_max_size, "%s", msg);
4250 OBJ(apm_battery_time) {
4252 msg = get_apm_battery_time();
4253 snprintf(p, p_max_size, "%s", msg);
4256 #endif /* __FreeBSD__ */
4260 snprintf(p, p_max_size, "%s", cur->mpd.title);
4263 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4266 snprintf(p, p_max_size, "%s", cur->mpd.album);
4269 snprintf(p, p_max_size, "%s", cur->mpd.random);
4272 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4275 snprintf(p, p_max_size, "%s", cur->mpd.track);
4278 snprintf(p, p_max_size, "%s", cur->mpd.name);
4281 snprintf(p, p_max_size, "%s", cur->mpd.file);
4284 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4287 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4290 snprintf(p, p_max_size, "%s", cur->mpd.status);
4293 int days = 0, hours = 0, minutes =
4295 int tmp = cur->mpd.elapsed;
4296 while (tmp >= 86400) {
4300 while (tmp >= 3600) {
4310 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4311 days, hours, minutes,
4314 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4317 snprintf(p, p_max_size, "%i:%02i", minutes,
4321 int days = 0, hours = 0, minutes =
4323 int tmp = cur->mpd.length;
4324 while (tmp >= 86400) {
4328 while (tmp >= 3600) {
4338 snprintf(p, p_max_size,
4339 "%i days %i:%02i:%02i",
4340 days, hours, minutes,
4343 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4346 snprintf(p, p_max_size, "%i:%02i", minutes,
4350 snprintf(p, p_max_size, "%2.0f",
4351 cur->mpd.progress * 100);
4354 new_bar(p, obj->data.pair.a,
4356 (int) (cur->mpd.progress *
4360 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4361 snprintf(p, p_max_size, "%s", cur->mpd.file);
4363 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4369 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4372 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4375 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4378 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4380 OBJ(xmms2_comment) {
4381 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4383 OBJ(xmms2_decoder) {
4384 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4386 OBJ(xmms2_transport) {
4387 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4390 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4393 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4396 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4398 OBJ(xmms2_tracknr) {
4399 if (cur->xmms2.tracknr != -1)
4400 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4402 OBJ(xmms2_bitrate) {
4403 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4406 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4409 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4411 OBJ(xmms2_elapsed) {
4412 int tmp = cur->xmms2.elapsed;
4413 snprintf(p, p_max_size, "%02d:%02d",
4414 tmp / 60000, (tmp / 1000) % 60);
4416 OBJ(xmms2_duration) {
4417 int tmp = cur->xmms2.duration;
4418 snprintf(p, p_max_size, "%02d:%02d",
4419 tmp / 60000, (tmp / 1000) % 60);
4421 OBJ(xmms2_percent) {
4422 snprintf(p, p_max_size, "%2.0f",
4423 cur->xmms2.progress * 100);
4426 new_bar(p, obj->data.pair.a,
4428 (int) (cur->xmms2.progress *
4432 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4433 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4435 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4440 OBJ(audacious_status) {
4441 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4443 OBJ(audacious_title) {
4444 snprintf(p, cur->audacious.max_title_len > 0 ?
4445 cur->audacious.max_title_len : p_max_size, "%s",
4446 cur->audacious.items[AUDACIOUS_TITLE]);
4448 OBJ(audacious_length) {
4449 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4451 OBJ(audacious_length_seconds) {
4452 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4454 OBJ(audacious_position) {
4455 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4457 OBJ(audacious_position_seconds) {
4458 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4460 OBJ(audacious_bitrate) {
4461 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4463 OBJ(audacious_frequency) {
4464 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4466 OBJ(audacious_channels) {
4467 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4469 OBJ(audacious_filename) {
4470 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4472 OBJ(audacious_playlist_length) {
4473 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4475 OBJ(audacious_playlist_position) {
4476 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4478 OBJ(audacious_bar) {
4480 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4481 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4482 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4487 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4490 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4493 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4496 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4499 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4502 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4506 if (obj->data.top.type == TOP_NAME
4507 && obj->data.top.num >= 0
4508 && obj->data.top.num < 10) {
4509 // if we limit the buffer and add a bunch of space after, it stops the thing from
4510 // moving other shit around, which is really fucking annoying
4511 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4512 } else if (obj->data.top.type == TOP_CPU
4513 && obj->data.top.num >= 0
4514 && obj->data.top.num < 10) {
4515 snprintf(p, 7, "%3.2f ",
4516 cur->cpu[obj->data.top.
4518 } else if (obj->data.top.type == TOP_PID
4519 && obj->data.top.num >= 0
4520 && obj->data.top.num < 10) {
4521 snprintf(p, 8, "%i ",
4522 cur->cpu[obj->data.top.
4524 } else if (obj->data.top.type == TOP_MEM
4525 && obj->data.top.num >= 0
4526 && obj->data.top.num < 10) {
4527 snprintf(p, 7, "%3.2f ",
4528 cur->cpu[obj->data.top.
4533 if (obj->data.top.type == TOP_NAME
4534 && obj->data.top.num >= 0
4535 && obj->data.top.num < 10) {
4536 // if we limit the buffer and add a bunch of space after, it stops the thing from
4537 // moving other shit around, which is really fucking annoying
4540 cur->memu[obj->data.top.
4542 } else if (obj->data.top.type == TOP_CPU
4543 && obj->data.top.num >= 0
4544 && obj->data.top.num < 10) {
4545 snprintf(p, 7, "%3.2f ",
4546 cur->memu[obj->data.top.
4548 } else if (obj->data.top.type == TOP_PID
4549 && obj->data.top.num >= 0
4550 && obj->data.top.num < 10) {
4551 snprintf(p, 8, "%i ",
4552 cur->memu[obj->data.top.
4554 } else if (obj->data.top.type == TOP_MEM
4555 && obj->data.top.num >= 0
4556 && obj->data.top.num < 10) {
4557 snprintf(p, 7, "%3.2f ",
4558 cur->memu[obj->data.top.
4565 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4566 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4568 obj->data.tail.last_update = current_update_time;
4572 tailstring *head = NULL;
4573 tailstring *headtmp = NULL;
4574 tailstring *freetmp = NULL;
4575 fp = fopen(obj->data.tail.logfile, "rt");
4577 ERR("tail logfile failed to open");
4580 obj->data.tail.readlines = 0;
4582 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
4589 addtail(&head, obj->data.tail.buffer);
4590 obj->data.tail.readlines++;
4596 if (obj->data.tail.readlines > 0) {
4597 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
4598 addtail(&headtmp, head->data);
4603 strcpy(obj->data.tail.buffer, headtmp->data);
4604 headtmp = headtmp->next;
4605 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
4607 strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
4608 headtmp = headtmp->next;
4612 /* get rid of any ugly newlines at the end */
4613 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
4614 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
4616 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4620 strcpy(obj->data.tail.buffer, "Logfile Empty");
4621 snprintf(p, p_max_size, "Logfile Empty");
4622 } /* if readlines */
4624 } /* if cur_upd_time >= */
4626 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4630 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4631 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4633 obj->data.tail.last_update = current_update_time;
4635 tailstring *head = NULL;
4636 tailstring *headtmp = NULL;
4637 tailstring *freetmp = NULL;
4638 fp = fopen(obj->data.tail.logfile, "rt");
4640 ERR("head logfile failed to open");
4642 obj->data.tail.readlines = 0;
4643 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
4644 addtail(&head, obj->data.tail.buffer);
4645 obj->data.tail.readlines++;
4649 if (obj->data.tail.readlines > 0) {
4651 addtail(&headtmp, head->data);
4656 strcpy(obj->data.tail.buffer, headtmp->data);
4657 headtmp = headtmp->next;
4659 strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
4660 headtmp = headtmp->next;
4663 /* get rid of any ugly newlines at the end */
4664 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
4665 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
4667 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4669 strcpy(obj->data.tail.buffer, "Logfile Empty");
4670 snprintf(p, p_max_size, "Logfile Empty");
4671 } /* if readlines > 0 */
4672 } /* if fp == null */
4673 } /* cur_upd_time >= */
4675 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4678 #ifdef TCP_PORT_MONITOR
4681 /* grab a pointer to this port monitor */
4682 tcp_port_monitor_t * p_monitor =
4683 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
4684 obj->data.tcp_port_monitor.port_range_begin,
4685 obj->data.tcp_port_monitor.port_range_end );
4687 snprintf(p, p_max_size, "monitor not found");
4691 /* now grab the text of interest */
4692 if ( peek_tcp_port_monitor( p_monitor,
4693 obj->data.tcp_port_monitor.item,
4694 obj->data.tcp_port_monitor.connection_index,
4695 p, p_max_size ) != 0 )
4697 snprintf(p, p_max_size, "monitor peek error");
4706 iconv_converting = 1;
4707 iconv_selected = obj->a;
4712 iconv_converting = 0;
4718 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
4720 OBJ(entropy_poolsize)
4722 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
4726 double entropy_perc;
4727 entropy_perc = (double)cur->entropy.entropy_avail /
4728 (double)cur->entropy.poolsize;
4729 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
4737 unsigned int a = strlen(p);
4740 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
4742 size_t dummy1, dummy2;
4743 char *ptr = buff_in;
4746 dummy1 = dummy2 = a;
4748 strncpy(buff_in, p, P_MAX_SIZE);
4750 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
4751 while (dummy1 > 0) {
4752 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
4754 ERR("Iconv codeset conversion failed");
4759 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
4770 double current_update_time, last_update_time;
4772 static void generate_text()
4774 struct information *cur = &info;
4782 current_update_time = get_time();
4786 /* add things to the buffer */
4792 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
4794 if (stuff_in_upper_case) {
4805 last_update_time = current_update_time;
4812 static void set_font()
4816 if (window.xftdraw != NULL) {
4817 XftDrawDestroy(window.xftdraw);
4819 window.xftdraw = XftDrawCreate(display, window.drawable,
4820 DefaultVisual(display,
4822 DefaultColormap(display,
4827 XSetFont(display, window.gc, fonts[selected_font].font->fid);
4833 static inline int get_string_width(const char *s)
4836 return *s ? calc_text_width(s, strlen(s)) : 0;
4842 static inline int get_string_width_special(char *s)
4855 if (*p == SPECIAL_CHAR) {
4856 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
4857 for (i = 0; i < strlen(p); i++) {
4858 *(p + i) = *(p + i + 1);
4860 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
4861 width += specials[special_index+index].width;
4868 if (strlen(final) > 1) {
4869 width += calc_text_width(final, strlen(final));
4879 static void text_size_updater(char *s);
4881 int last_font_height;
4882 static void update_text_area()
4886 /* update text size if it isn't fixed */
4891 text_width = minimum_width;
4894 last_font_height = font_height();
4895 for_each_line(text_buffer, text_size_updater);
4897 if (text_height < minimum_height)
4898 text_height = minimum_height;
4899 if (text_width > maximum_width && maximum_width > 0)
4900 text_width = maximum_width;
4903 /* get text position on workarea */
4904 switch (text_alignment) {
4911 x = workarea[2] - text_width - gap_x;
4918 y = workarea[3] - text_height - gap_y;
4922 x = workarea[2] - text_width - gap_x;
4923 y = workarea[3] - text_height - gap_y;
4927 case NONE: // Let the WM manage the window
4938 if (own_window && !fixed_pos) {
4941 text_start_x = border_margin + 1;
4942 text_start_y = border_margin + 1;
4943 window.x = x - border_margin - 1;
4944 window.y = y - border_margin - 1;
4948 /* If window size doesn't match to workarea's size, then window
4949 * probably includes panels (gnome).
4950 * Blah, doesn't work on KDE. */
4951 if (workarea[2] != window.width
4952 || workarea[3] != window.height) {
4966 static int cur_x, cur_y; /* current x and y for drawing */
4967 static int draw_mode; /* FG, BG or OUTLINE */
4968 static long current_color;
4971 static void text_size_updater(char *s)
4975 /* get string widths and skip specials */
4978 if (*p == SPECIAL_CHAR) {
4980 w += get_string_width(s);
4983 if (specials[special_index].type == BAR
4984 || specials[special_index].type == GRAPH) {
4985 w += specials[special_index].width;
4986 if (specials[special_index].height > last_font_height) {
4987 last_font_height = specials[special_index].height;
4988 last_font_height += font_ascent();
4990 } else if (specials[special_index].type == OFFSET) {
4991 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
4992 } else if (specials[special_index].type == VOFFSET) {
4993 last_font_height += specials[special_index].arg;
4994 } else if (specials[special_index].type == GOTO) {
4995 if (specials[special_index].arg >= 0)
4996 w += (int)specials[special_index].arg - cur_x;
4997 } else if (specials[special_index].type == TAB) {
4998 int start = specials[special_index].arg;
4999 int step = specials[special_index].width;
5000 if (!step || step < 0)
5002 w += step - (cur_x - text_start_x - start) % step;
5003 } else if (specials[special_index].type == FONT) {
5004 selected_font = specials[special_index].font_added;
5005 if (font_height() > last_font_height) {
5006 last_font_height = font_height();
5015 w += get_string_width(s);
5016 if (w > text_width) {
5019 if (text_width > maximum_width && maximum_width) {
5020 text_width = maximum_width;
5023 text_height += last_font_height;
5024 last_font_height = font_height();
5028 static inline void set_foreground_color(long c)
5031 XSetForeground(display, window.gc, c);
5035 static void draw_string(const char *s)
5039 int i, i2, pos, width_of_s;
5042 width_of_s = get_string_width(s);
5043 if (out_to_console) {
5045 fflush(stdout); /* output immediately, don't buffer */
5047 /* daemon_run(s); the daemon can be called here, but we need to have a buffer in daemon_run() and we need to tell it when everything is ready to be sent */
5048 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5049 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5050 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5054 snprintf(space, 2, " ");
5056 max = ((text_width - width_of_s) / get_string_width(space));
5059 * This code looks for tabs in the text and coverts them to spaces.
5060 * The trick is getting the correct number of spaces,
5061 * and not going over the window's size without forcing
5062 * the window larger.
5064 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5065 if (tmpstring1[i] == '\t') // 9 is ascii tab
5069 i2 < (8 - (1 + pos) % 8) && added <= max;
5072 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5073 fprintf(stderr,"buffer overrun detected\n");
5075 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5080 if (tmpstring1[i] != 9) {
5082 if ( pos > TEXT_BUFFER_SIZE-1 )
5083 fprintf(stderr,"buffer overrun detected\n");
5085 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5091 if (text_width == maximum_width) {
5092 /* this means the text is probably pushing the limit, so we'll chop it */
5093 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5094 tmpstring2[strlen(tmpstring2)-1] = '\0';
5104 c.pixel = current_color;
5105 XQueryColor(display, DefaultColormap(display, screen), &c);
5108 c2.color.red = c.red;
5109 c2.color.green = c.green;
5110 c2.color.blue = c.blue;
5111 c2.color.alpha = fonts[selected_font].font_alpha;
5113 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5114 cur_x, cur_y, (XftChar8 *) s,
5117 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5118 cur_x, cur_y, (XftChar8 *) s,
5124 XDrawString(display, window.drawable, window.gc,
5125 cur_x, cur_y, s, strlen(s));
5127 cur_x += width_of_s;
5129 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5132 long redmask, greenmask, bluemask;
5134 void set_up_gradient()
5137 colour_depth = DisplayPlanes(display, screen);
5141 if (colour_depth != 24 && colour_depth != 16) {
5142 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5148 for(i = (colour_depth / 3)-1; i>=0; i--) {
5150 greenmask |= 1 << i;
5153 if (colour_depth%3 == 1) {
5154 greenmask |= 1 << (colour_depth / 3);
5156 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5157 greenmask = greenmask << (colour_depth / 3);
5160 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 */
5162 int red1, green1, blue1; // first colour
5163 int red2, green2, blue2; // second colour
5164 int red3 = 0, green3 = 0, blue3 = 0; // difference
5165 short redshift = (2*colour_depth / 3 + colour_depth%3);
5166 short greenshift = (colour_depth / 3);
5167 red1 = (first_colour & redmask) >> redshift;
5168 green1 = (first_colour & greenmask) >> greenshift;
5169 blue1 = first_colour & bluemask;
5170 red2 = (last_colour & redmask) >> redshift;
5171 green2 = (last_colour & greenmask) >> greenshift;
5172 blue2 = last_colour & bluemask;
5179 if (green1 > green2) {
5182 if (green1 < green2) {
5185 if (blue1 > blue2) {
5188 if (blue1 < blue2) {
5203 if (red1 > bluemask) {
5206 if (green1 > bluemask) {
5209 if (blue1 > bluemask) {
5212 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5216 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5217 if (colour_depth == 0) {
5220 int red1, green1, blue1; // first colour
5221 int red2, green2, blue2; // second colour
5222 long redshift = (2*colour_depth / 3 + colour_depth%3);
5223 long greenshift = (colour_depth / 3);
5224 int red3 = 0, green3 = 0, blue3 = 0; // difference
5225 red1 = (first_colour & redmask) >> redshift;
5226 green1 = (first_colour & greenmask) >> greenshift;
5227 blue1 = first_colour & bluemask;
5228 red2 = (last_colour & redmask) >> redshift;
5229 green2 = (last_colour & greenmask) >> greenshift;
5230 blue2 = last_colour & bluemask;
5231 red3 = abs(red1 - red2);
5232 green3 = abs(green1 - green2);
5233 blue3 = abs(blue1 - blue2);
5242 static void draw_line(char *s)
5246 cur_x = text_start_x;
5247 cur_y += font_ascent();
5249 short font_h = font_height();
5251 /* find specials and draw stuff */
5254 if (*p == SPECIAL_CHAR) {
5257 /* draw string before special */
5264 switch (specials[special_index].type) {
5265 case HORIZONTAL_LINE:
5268 specials[special_index].height;
5269 int mid = font_ascent() / 2;
5270 w = text_start_x + text_width -
5273 XSetLineAttributes(display,
5278 XDrawLine(display, window.drawable,
5289 specials[special_index].height;
5291 specials[special_index].arg;
5292 int mid = font_ascent() / 2;
5293 char ss[2] = { s, s };
5294 w = text_start_x + text_width -
5297 XSetLineAttributes(display,
5302 XSetDashes(display, window.gc, 0,
5304 XDrawLine(display, window.drawable,
5314 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5318 specials[special_index].height;
5320 specials[special_index].arg;
5321 int by = cur_y - (font_ascent() / 2) - 1;
5322 if (h < font_height()) {
5325 w = specials[special_index].width;
5328 text_width - cur_x - 1;
5332 XSetLineAttributes(display,
5338 XDrawRectangle(display,
5342 XFillRectangle(display,
5346 w * bar_usage / 255,
5348 if (specials[special_index].
5350 && specials[special_index].
5354 [special_index].height;
5361 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5365 specials[special_index].height;
5366 unsigned long last_colour = current_color;
5367 int by = cur_y - (font_ascent()/2) - 1;
5368 if (h < font_height()) {
5371 w = specials[special_index].width;
5373 w = text_start_x + text_width - cur_x - 1;
5376 if (draw_graph_borders) {
5377 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5378 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5380 XSetLineAttributes(display,
5387 int gradient_size = 0;
5388 float gradient_factor = 0;
5389 float gradient_update = 0;
5390 unsigned long tmpcolour = current_color;
5391 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5392 tmpcolour = specials[special_index].last_colour;
5393 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5394 gradient_factor = (float)gradient_size / (w - 2);
5396 for (i = w - 2; i > -1; i--) {
5397 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5398 XSetForeground(display, window.gc, tmpcolour);
5399 gradient_update += gradient_factor;
5400 while (gradient_update > 0) {
5401 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5405 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5408 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 */
5410 if (specials[special_index].
5412 && specials[special_index].
5416 [special_index].height;
5418 /* if (draw_mode == BG) {
5419 set_foreground_color(default_bg_color);
5421 else if (draw_mode == OUTLINE) {
5422 set_foreground_color(default_out_color);
5424 set_foreground_color(default_fg_color);
5426 set_foreground_color(last_colour);
5432 int old = font_ascent();
5433 cur_y -= font_ascent();
5434 selected_font = specials[special_index].font_added;
5435 if (cur_y + font_ascent() < cur_y + old) {
5438 cur_y += font_ascent();
5444 if (draw_mode == FG)
5445 set_foreground_color(specials
5451 if (draw_mode == BG)
5452 set_foreground_color(specials
5458 if (draw_mode == OUTLINE)
5459 set_foreground_color(specials
5465 w += specials[special_index].arg;
5469 cur_y += specials[special_index].arg;
5473 if (specials[special_index].arg >= 0)
5474 cur_x = (int)specials[special_index].arg;
5479 int start = specials[special_index].arg;
5480 int step = specials[special_index].width;
5481 if (!step || step < 0)
5483 w = step - (cur_x - text_start_x - start) % step;
5489 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5490 /*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);*/
5491 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5492 cur_x = pos_x - specials[special_index].arg;
5499 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5500 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5501 /*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);*/
5503 specials[special_index].arg)
5506 [special_index].arg;
5523 if (cur_y_add > 0) {
5525 cur_y -= font_descent();
5530 cur_y += font_descent();
5534 static void draw_text()
5537 cur_y = text_start_y;
5540 if (draw_borders && border_width > 0) {
5541 unsigned int b = (border_width + 1) / 2;
5543 if (stippled_borders) {
5545 { stippled_borders, stippled_borders };
5546 XSetLineAttributes(display, window.gc,
5547 border_width, LineOnOffDash,
5548 CapButt, JoinMiter);
5549 XSetDashes(display, window.gc, 0, ss, 2);
5551 XSetLineAttributes(display, window.gc,
5552 border_width, LineSolid,
5553 CapButt, JoinMiter);
5556 XDrawRectangle(display, window.drawable, window.gc,
5557 text_start_x - border_margin + b,
5558 text_start_y - border_margin + b,
5559 text_width + border_margin * 2 - 1 - b * 2,
5560 text_height + border_margin * 2 - 1 -
5567 for_each_line(text_buffer, draw_line);
5570 static void draw_stuff()
5574 if (draw_shades && !draw_outline) {
5577 set_foreground_color(default_bg_color);
5587 for (i = -1; i < 2; i++)
5588 for (j = -1; j < 2; j++) {
5589 if (i == 0 && j == 0)
5593 set_foreground_color(default_out_color);
5594 draw_mode = OUTLINE;
5601 set_foreground_color(default_fg_color);
5609 swap.swap_window = window.window;
5610 swap.swap_action = XdbeBackground;
5611 XdbeSwapBuffers(display, &swap, 1);
5617 static void clear_text(int exposures)
5621 return; /* The swap action is XdbeBackground, which clears */
5625 /* there is some extra space for borders and outlines */
5626 XClearArea(display, window.window,
5627 text_start_x - border_margin - 1,
5628 text_start_y - border_margin - 1,
5629 text_width + border_margin * 2 + 2,
5630 text_height + border_margin * 2 + 2,
5631 exposures ? True : 0);
5636 static int need_to_update;
5638 /* update_text() generates new text and clears old text area */
5639 static void update_text()
5648 static void main_loop()
5650 #ifdef SIGNAL_BLOCKING
5651 sigset_t newmask, oldmask;
5653 sigemptyset(&newmask);
5654 sigaddset(&newmask,SIGINT);
5655 sigaddset(&newmask,SIGTERM);
5656 sigaddset(&newmask,SIGUSR1);
5660 Region region = XCreateRegion();
5662 int event_base, error_base;
5663 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
5664 ERR("Xdamage extension unavailable");
5666 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
5667 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
5668 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
5669 #endif /* HAVE_XDAMAGE */
5673 while (total_run_times == 0 || info.looped < total_run_times) {
5676 #ifdef SIGNAL_BLOCKING
5677 /* block signals. we will inspect for pending signals later */
5678 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
5679 CRIT_ERR("unable to sigprocmask()");
5685 /* wait for X event or timeout */
5687 if (!XPending(display)) {
5692 update_interval - (get_time() -
5698 tv.tv_sec = (long) t;
5699 tv.tv_usec = (long) (t * 1000000) % 1000000;
5701 FD_SET(ConnectionNumber(display), &fdsr);
5704 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
5707 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
5712 ERR("can't select(): %s",
5723 if (need_to_update) {
5725 int wx = window.x, wy = window.y;
5733 /* resize window if it isn't right size */
5735 (text_width + border_margin * 2 + 1 !=
5737 || text_height + border_margin * 2 + 1 !=
5741 border_margin * 2 + 1;
5744 border_margin * 2 + 1;
5745 XResizeWindow(display,
5750 set_transparent_background(window.window);
5754 /* move window if it isn't in right position */
5757 || window.y != wy)) {
5758 XMoveWindow(display, window.window,
5759 window.x, window.y);
5769 r.x = text_start_x - border_margin;
5770 r.y = text_start_y - border_margin;
5771 r.width = text_width + border_margin * 2;
5772 r.height = text_height + border_margin * 2;
5773 XUnionRectWithRegion(&r, region, region);
5778 /* handle X events */
5780 while (XPending(display)) {
5782 XNextEvent(display, &ev);
5789 r.width = ev.xexpose.width;
5790 r.height = ev.xexpose.height;
5791 XUnionRectWithRegion(&r, region,
5797 case ReparentNotify:
5798 /* set background to ParentRelative for all parents */
5800 set_transparent_background(window.
5805 case ConfigureNotify:
5807 /* if window size isn't what expected, set fixed size */
5808 if (ev.xconfigure.width !=
5810 || ev.xconfigure.height !=
5812 if (window.width != 0
5813 && window.height != 0)
5816 /* clear old stuff before screwing up size and pos */
5822 if (XGetWindowAttributes(display, window.window, &attrs)) {
5837 border_margin * 2 - 1;
5840 border_margin * 2 - 1;
5841 if (text_width > maximum_width && maximum_width > 0)
5842 text_width = maximum_width;
5845 /* if position isn't what expected, set fixed pos, total_updates
5846 * avoids setting fixed_pos when window is set to weird locations
5848 /*if (total_updates >= 2 this is broken
5850 && (window.x != ev.xconfigure.x
5853 && (ev.xconfigure.x != 0
5854 || ev.xconfigure.y != 0)) {
5864 /* forward the click to the desktop window */
5865 XUngrabPointer(display, ev.xbutton.time);
5866 ev.xbutton.window = window.desktop;
5867 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
5874 /* forward the release to the desktop window */
5875 ev.xbutton.window = window.desktop;
5876 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
5884 if (ev.type == event_base + XDamageNotify) {
5885 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
5886 XFixesSetRegion(display, part, &dev->area, 1);
5887 XFixesUnionRegion(display, region2, region2, part);
5889 #endif /* HAVE_XDAMAGE */
5894 XDamageSubtract(display, damage, region2, None);
5895 XFixesSetRegion(display, region2, 0, 0);
5896 #endif /* HAVE_XDAMAGE */
5898 /* XDBE doesn't seem to provide a way to clear the back buffer without
5899 * interfering with the front buffer, other than passing XdbeBackground
5900 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
5901 * redraw the text even if it wasn't part of the exposed area. OTOH,
5902 * if we're not going to call draw_stuff at all, then no swap happens
5903 * and we can safely do nothing.
5906 if (!XEmptyRegion(region)) {
5910 r.x = text_start_x - border_margin;
5911 r.y = text_start_y - border_margin;
5912 r.width = text_width + border_margin * 2;
5913 r.height = text_height + border_margin * 2;
5914 XUnionRectWithRegion(&r, region, region);
5917 XSetRegion(display, window.gc, region);
5920 XftDrawSetClip(window.xftdraw, region);
5926 XDestroyRegion(region);
5927 region = XCreateRegion();
5931 #ifdef SIGNAL_BLOCKING
5932 /* unblock signals of interest and let handler fly */
5933 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
5934 CRIT_ERR("unable to sigprocmask()");
5937 switch(g_signal_pending) {
5940 ERR("received SIGUSR1. reloading the config file.");
5947 ERR("received SIGINT or SIGTERM to terminate. bye!");
5950 XDestroyRegion(region);
5953 return; /* return from main_loop */
5958 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
5959 * but didn't write any code to deal with it. if you don't want to
5960 * handle a signal, don't set a handler on it in the first place. */
5961 if (g_signal_pending)
5962 ERR("ignoring signal (%d)", g_signal_pending);
5969 #if defined(X11) && defined(HAVE_XDAMAGE)
5970 XDamageDestroy(display, damage);
5971 XFixesDestroyRegion(display, region2);
5972 XFixesDestroyRegion(display, part);
5973 XDestroyRegion(region);
5975 #endif /* X11 && HAVE_XDAMAGE */
5978 static void load_config_file(const char *);
5980 /* reload the config file */
5981 void reload_config(void)
5983 timed_thread_destroy_registered_threads ();
5985 if (info.cpu_usage) {
5986 free(info.cpu_usage);
5987 info.cpu_usage = NULL;
5990 #ifdef TCP_PORT_MONITOR
5991 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
5994 if (current_config) {
5996 load_config_file(current_config);
5998 /* re-init specials array */
5999 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6000 ERR("failed to realloc specials array");
6005 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6008 #ifdef TCP_PORT_MONITOR
6009 info.p_tcp_port_monitor_collection = NULL;
6012 if (create_audacious_thread() !=0)
6013 CRIT_ERR("unable to create audacious thread!");
6014 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6016 extract_variable_text(text);
6025 timed_thread_destroy_registered_threads ();
6027 if (info.cpu_usage) {
6028 free(info.cpu_usage);
6029 info.cpu_usage = NULL;
6034 XdbeDeallocateBackBufferName(display, window.back_buffer);
6040 XDestroyWindow(display, window.window);
6041 XClearWindow(display, RootWindow(display, screen));
6047 XClearWindow(display, RootWindow(display, screen));
6052 XFreeGC(display, window.gc);
6055 free_text_objects(text_object_count, text_objects);
6056 text_object_count = 0;
6057 text_objects = NULL;
6059 if (text != original_text)
6062 free(current_config);
6063 free(current_mail_spool);
6065 #ifdef TCP_PORT_MONITOR
6066 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6067 info.p_tcp_port_monitor_collection = NULL;
6076 static int string_to_bool(const char *s)
6080 if (strcasecmp(s, "yes") == 0)
6082 if (strcasecmp(s, "true") == 0)
6084 if (strcasecmp(s, "1") == 0)
6089 static enum alignment string_to_alignment(const char *s)
6091 if (strcasecmp(s, "top_left") == 0)
6093 else if (strcasecmp(s, "top_right") == 0)
6095 else if (strcasecmp(s, "bottom_left") == 0)
6097 else if (strcasecmp(s, "bottom_right") == 0)
6098 return BOTTOM_RIGHT;
6099 else if (strcasecmp(s, "tl") == 0)
6101 else if (strcasecmp(s, "tr") == 0)
6103 else if (strcasecmp(s, "bl") == 0)
6105 else if (strcasecmp(s, "br") == 0)
6106 return BOTTOM_RIGHT;
6107 else if (strcasecmp(s, "none") == 0)
6114 static void set_default_configurations(void)
6116 fork_to_background = 0;
6117 total_run_times = 0;
6118 info.cpu_avg_samples = 2;
6119 info.net_avg_samples = 2;
6124 strcpy(info.mpd.host, "localhost");
6125 info.mpd.port = 6600;
6126 info.mpd.status = NULL;
6127 info.mpd.artist = NULL;
6128 info.mpd.album = NULL;
6129 info.mpd.title = NULL;
6130 info.mpd.random = NULL;
6131 info.mpd.track = NULL;
6132 info.mpd.name = NULL;
6133 info.mpd.file = NULL;
6136 info.xmms2.artist = NULL;
6137 info.xmms2.album = NULL;
6138 info.xmms2.title = NULL;
6139 info.xmms2.genre = NULL;
6140 info.xmms2.comment = NULL;
6141 info.xmms2.decoder = NULL;
6142 info.xmms2.transport = NULL;
6143 info.xmms2.url = NULL;
6144 info.xmms2.status = NULL;
6153 default_fg_color = WhitePixel(display, screen);
6154 default_bg_color = BlackPixel(display, screen);
6155 default_out_color = BlackPixel(display, screen);
6158 draw_graph_borders = 1;
6160 set_first_font("6x10");
6168 window.type=TYPE_NORMAL;
6170 strcpy(window.wm_class_name, "conky");
6172 stippled_borders = 0;
6175 text_alignment = BOTTOM_LEFT;
6178 free(current_mail_spool);
6181 variable_substitute(MAIL_FILE, buf, 256);
6183 current_mail_spool = strdup(buf);
6187 update_interval = 10.0;
6188 stuff_in_upper_case = 0;
6190 #ifdef TCP_PORT_MONITOR
6191 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6192 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6196 static void load_config_file(const char *f)
6198 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6202 set_default_configurations();
6208 char buf[256], *p, *p2, *name, *value;
6210 if (fgets(buf, 256, fp) == NULL)
6215 /* break at comment */
6216 p2 = strchr(p, '#');
6221 while (*p && isspace((int) *p))
6224 continue; /* empty line */
6230 while (*p2 && !isspace((int) *p2))
6233 *p2 = '\0'; /* break at name's end */
6240 while (*p && isspace((int) *p))
6245 p2 = value + strlen(value);
6246 while (isspace((int) *(p2 - 1)))
6252 #define CONF2(a) if (strcasecmp(name, a) == 0)
6253 #define CONF(a) else CONF2(a)
6254 #define CONF3(a,b) \
6255 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6259 CONF2("alignment") {
6261 int a = string_to_alignment(value);
6269 CONF("background") {
6270 fork_to_background = string_to_bool(value);
6274 CONF2("background") {
6275 fork_to_background = string_to_bool(value);
6279 CONF("border_margin") {
6281 border_margin = strtol(value, 0, 0);
6285 CONF("border_width") {
6287 border_width = strtol(value, 0, 0);
6291 CONF("default_color") {
6293 default_fg_color = get_x11_color(value);
6297 CONF3("default_shade_color", "default_shadecolor") {
6299 default_bg_color = get_x11_color(value);
6303 CONF3("default_outline_color", "default_outlinecolor") {
6305 default_out_color = get_x11_color(value);
6312 info.mail = parse_mail_args(IMAP, value);
6319 info.mail = parse_mail_args(POP3, value);
6327 strncpy(info.mpd.host, value, 127);
6333 info.mpd.port = strtol(value, 0, 0);
6334 if (info.mpd.port < 1
6335 || info.mpd.port > 0xffff)
6339 CONF("mpd_password") {
6341 strncpy(info.mpd.password, value, 127);
6346 CONF("cpu_avg_samples") {
6348 cpu_avg_samples = strtol(value, 0, 0);
6349 if (cpu_avg_samples < 1
6350 || cpu_avg_samples > 14)
6359 CONF("net_avg_samples") {
6361 net_avg_samples = strtol(value, 0, 0);
6362 if (net_avg_samples < 1
6363 || net_avg_samples > 14)
6379 CONF("double_buffer") {
6380 use_xdbe = string_to_bool(value);
6384 CONF("override_utf8_locale") {
6385 utf8_mode = string_to_bool(value);
6388 CONF("draw_borders") {
6389 draw_borders = string_to_bool(value);
6391 CONF("draw_graph_borders") {
6392 draw_graph_borders = string_to_bool(value);
6394 CONF("draw_shades") {
6395 draw_shades = string_to_bool(value);
6397 CONF("draw_outline") {
6398 draw_outline = string_to_bool(value);
6401 CONF("out_to_console") {
6402 out_to_console = string_to_bool(value);
6404 CONF("use_spacer") {
6405 use_spacer = string_to_bool(value);
6410 use_xft = string_to_bool(value);
6414 set_first_font(value);
6419 if (value && font_count >= 0)
6420 fonts[0].font_alpha = atof(value)
6429 if (string_to_bool(value))
6430 ERR("Xft not enabled");
6433 /* xftfont silently ignored when no Xft */
6436 /* xftalpha is silently ignored when no Xft */
6441 set_first_font(value);
6450 gap_x = atoi(value);
6456 gap_y = atoi(value);
6461 CONF("mail_spool") {
6464 variable_substitute(value, buf, 256);
6468 if (current_mail_spool)
6469 free(current_mail_spool);
6470 current_mail_spool = strdup(buf);
6476 CONF("minimum_size") {
6479 (value, "%d %d", &minimum_width,
6480 &minimum_height) != 2)
6483 &minimum_width) != 1)
6488 CONF("maximum_width") {
6490 if (sscanf(value, "%d", &maximum_width) != 1)
6496 CONF("no_buffers") {
6497 no_buffers = string_to_bool(value);
6499 CONF("pad_percents") {
6500 pad_percents = atoi(value);
6504 CONF("own_window") {
6505 own_window = string_to_bool(value);
6507 CONF("wm_class_name") {
6508 memset(window.wm_class_name,0,sizeof(window.wm_class_name));
6509 strncpy(window.wm_class_name, value, sizeof(window.wm_class_name)-1);
6511 CONF("own_window_transparent") {
6512 set_transparent = string_to_bool(value);
6514 CONF("own_window_colour") {
6516 background_colour = get_x11_color(value);
6518 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
6521 CONF("own_window_hints") {
6523 char *p_hint, *p_save;
6524 char delim[] = ", ";
6526 /* tokenize the value into individual hints */
6527 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
6529 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
6530 if (strncmp(p_hint,"undecorate",10) == 0)
6531 SET_HINT(window.hints,HINT_UNDECORATED);
6532 else if (strncmp(p_hint,"below",5) == 0)
6533 SET_HINT(window.hints,HINT_BELOW);
6534 else if (strncmp(p_hint,"above",5) == 0)
6535 SET_HINT(window.hints,HINT_ABOVE);
6536 else if (strncmp(p_hint,"sticky",6) == 0)
6537 SET_HINT(window.hints,HINT_STICKY);
6538 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
6539 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
6540 else if (strncmp(p_hint,"skip_pager",10) == 0)
6541 SET_HINT(window.hints,HINT_SKIP_PAGER);
6545 p_hint=strtok_r(NULL, delim, &p_save);
6547 while (p_hint!=NULL);
6550 CONF("own_window_type") {
6552 if (strncmp(value,"normal",6)==0)
6553 window.type = TYPE_NORMAL;
6554 else if (strncmp(value,"desktop",7)==0)
6555 window.type = TYPE_DESKTOP;
6556 else if (strncmp(value,"override",8)==0)
6557 window.type = TYPE_OVERRIDE;
6563 CONF("stippled_borders") {
6565 stippled_borders = strtol(value, 0, 0);
6567 stippled_borders = 4;
6571 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
6574 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
6576 CONF("update_interval") {
6578 update_interval = strtod(value, 0);
6582 CONF("total_run_times") {
6584 total_run_times = strtod(value, 0);
6589 stuff_in_upper_case = string_to_bool(value);
6591 CONF("max_specials") {
6593 max_specials = atoi(value);
6597 CONF("max_user_text") {
6599 max_user_text = atoi(value);
6604 if (text != original_text)
6614 int l = strlen(text);
6615 if (fgets(buf, 256, fp) == NULL)
6618 realloc(text, l + strlen(buf)
6622 if (strlen(text) > max_user_text)
6626 text_lines = line + 1;
6629 #ifdef TCP_PORT_MONITOR
6630 CONF("min_port_monitors")
6633 (sscanf(value, "%d", &tcp_port_monitor_collection_args.min_port_monitors) != 1) ||
6634 tcp_port_monitor_collection_args.min_port_monitors < 0 )
6636 /* an error. use default, warn and continue. */
6637 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6640 else if ( tcp_port_monitor_collection_args.min_port_monitors == 0 )
6642 /* no error, just use default */
6643 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6645 /* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
6647 CONF("min_port_monitor_connections")
6650 (sscanf(value, "%d", &tcp_port_monitor_args.min_port_monitor_connections) != 1)
6651 || tcp_port_monitor_args.min_port_monitor_connections < 0 )
6653 /* an error. use default, warni and continue. */
6654 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6657 else if ( tcp_port_monitor_args.min_port_monitor_connections == 0 )
6659 /* no error, just use default */
6660 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6662 /* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
6666 ERR("%s: %d: no such configuration: '%s'", f, line, name);
6678 /* : means that character before that takes an argument */
6679 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
6692 int main(int argc, char **argv)
6694 struct sigaction act, oact;
6697 memset(&info, 0, sizeof(info) );
6699 #ifdef TCP_PORT_MONITOR
6700 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
6701 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
6704 /* handle command line parameters that don't change configs */
6709 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
6710 *s) || ((s = getenv("LANG")) && *s)) {
6711 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
6713 ERR("malloc failed");
6715 for (x = 0; x < strlen(s); x++) {
6716 temp[x] = tolower(s[x]);
6718 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
6724 if (!setlocale(LC_CTYPE, "")) {
6725 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
6729 int c = getopt(argc,
6740 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
6741 * though free() does the NULL check itself;), then load optarg value */
6743 free(current_config);
6744 current_config = strdup(optarg);
6749 ("Usage: %s [OPTION]...\n"
6750 "Conky is a system monitor that renders text on desktop or to own transparent\n"
6751 "window. Command line options will override configurations defined in config\n"
6754 " -c FILE config file to load instead of "
6757 " -d daemonize, fork to background\n"
6760 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
6761 " -f FONT font to use\n"
6763 " -o create own window to draw\n"
6766 " -b double buffer (prevents flickering)\n"
6768 " -w WIN_ID window id to draw\n"
6769 " -x X x position\n"
6770 " -y Y y position\n"
6772 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
6773 " -u SECS update interval\n"
6774 " -i NUM number of times to update Conky\n", argv[0]);
6778 window.window = strtol(optarg, 0, 0);
6787 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
6791 /* load current_config or CONFIG_FILE */
6794 if (current_config == NULL) {
6795 /* load default config file */
6798 variable_substitute(CONFIG_FILE, buf, 256);
6801 current_config = strdup(buf);
6805 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
6806 load_config_file(current_config);
6808 set_default_configurations();
6811 /* init specials array */
6812 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
6813 ERR("failed to create specials array");
6816 if (current_mail_spool == NULL) {
6818 variable_substitute(MAIL_FILE, buf, 256);
6821 current_mail_spool = strdup(buf);
6825 /* handle other command line arguments */
6827 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
6828 optind = optreset = 1;
6833 #if defined(__FreeBSD__)
6834 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
6835 O_RDONLY, "kvm_open")) == NULL)
6836 CRIT_ERR( "cannot read kvm");
6840 int c = getopt(argc,
6848 fork_to_background = 1;
6853 set_first_font(optarg);
6856 text_alignment = string_to_alignment(optarg);
6871 if (text != original_text)
6873 text = strdup(optarg);
6874 convert_escapes(text);
6878 update_interval = strtod(optarg, 0);
6882 total_run_times = strtod(optarg, 0);
6886 gap_x = atoi(optarg);
6890 gap_y = atoi(optarg);
6904 /* generate text and get initial size */
6905 extract_variable_text(text);
6906 if (text != original_text) {
6911 if (fork_to_background) {
6915 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
6921 fprintf(stderr,"\n"); fflush(stderr);
6925 /* parent process */
6926 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
6936 update_text_area(); /* to get initial size of the window */
6940 text_width + border_margin * 2 + 1,
6941 text_height + border_margin * 2 + 1,
6942 set_transparent, background_colour, info.uname_s.nodename, argv, argc);
6945 update_text_area(); /* to position text/window on screen */
6950 if (own_window && !fixed_pos) {
6951 XMoveWindow(display, window.window, window.x, window.y);
6954 set_transparent_background(window.window);
6965 /* Set signal handlers */
6966 act.sa_handler = signal_handler;
6967 sigemptyset(&act.sa_mask);
6970 act.sa_flags |= SA_RESTART;
6973 if ( sigaction(SIGINT,&act,&oact) < 0 ||
6974 sigaction(SIGUSR1,&act,&oact) < 0 ||
6975 sigaction(SIGTERM,&act,&oact) < 0 )
6977 ERR("error setting signal handler: %s", strerror(errno) );
6981 if (create_audacious_thread() !=0)
6982 CRIT_ERR("unable to create audacious thread!");
6983 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6988 #if defined(__FreeBSD__)
6995 void signal_handler(int sig)
6997 /* signal handler is light as a feather, as it should be.
6998 * we will poll g_signal_pending with each loop of conky
6999 * and do any signal processing there, NOT here. */
7000 g_signal_pending=sig;