1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
45 #include <X11/Xutil.h>
47 #include <X11/extensions/Xdamage.h>
53 #include <sys/types.h>
55 #include <netinet/in.h>
67 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
70 #define CONFIG_FILE "$HOME/.conkyrc"
71 #define MAIL_FILE "$MAIL"
72 #define MAX_IF_BLOCK_DEPTH 5
74 /* #define SIGNAL_BLOCKING */
75 #undef SIGNAL_BLOCKING
77 static void print_version()
79 printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
81 printf("\nCompiled in features:\n\n"
82 "system config file: %s\n\n"
86 " * Xdamage extension\n"
87 # endif /* HAVE_XDAMAGE */
89 " * Xdbe extension (double buffer)\n"
90 # endif /* HAVE_XDBE */
95 "\n Music detection:\n"
98 #endif /* AUDACIOUS */
108 "\n General features:\n"
112 #ifdef TCP_PORT_MONITOR
114 #endif /* TCP_PORT_MONITOR */
121 "", SYSTEM_CONFIG_FILE
131 static int text_start_x, text_start_y; /* text start position in window */
132 static int text_width, text_height;
146 char name[TEXT_BUFFER_SIZE];
156 static int selected_font = 0;
157 static int font_count = -1;
158 struct font_list *fonts = NULL;
160 static char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
164 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
165 fonts[selected_font].xftfont->descent) \
166 : (fonts[selected_font].font->max_bounds.ascent + \
167 fonts[selected_font].font->max_bounds.descent))
168 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
169 : fonts[selected_font].font->max_bounds.ascent)
170 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
171 : fonts[selected_font].font->max_bounds.descent)
175 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
176 fonts[selected_font].font->max_bounds.descent)
177 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
178 #define font_descent() fonts[selected_font].font->max_bounds.descent
182 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
184 static void set_font();
186 int addfont(const char *data_in)
188 if (font_count > MAX_FONTS) {
189 CRIT_ERR("you don't need that many fonts, sorry.");
192 if (font_count == 0) {
196 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
201 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
203 CRIT_ERR("realloc in addfont");
205 // must account for null terminator
206 if (strlen(data_in) < TEXT_BUFFER_SIZE) {
207 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
209 fonts[font_count].font_alpha = 0xffff;
212 CRIT_ERR("Oops...looks like something overflowed in addfont().");
217 void set_first_font(const char *data_in)
219 if (font_count < 0) {
220 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
226 if (strlen(data_in) > 1) {
227 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE - 1);
229 fonts[0].font_alpha = 0xffff;
238 for (i = 0; i <= font_count; i++) {
241 XftFontClose(display, fonts[i].xftfont);
245 XFreeFont(display, fonts[i].font);
254 static void load_fonts()
258 for (i = 0; i <= font_count; i++) {
262 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
263 XftFontClose(display, fonts[i].xftfont);
265 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
266 fonts[i].name)) != NULL) {
270 ERR("can't load Xft font '%s'", fonts[i].name);
271 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
272 "courier-12")) != NULL) {
276 ERR("can't load Xft font '%s'", "courier-12");
278 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
279 CRIT_ERR("can't load font '%s'", "fixed");
286 /* load normal font */
287 /* if (fonts[i].font != NULL) {
288 XFreeFont(display, fonts[i].font);
291 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
292 ERR("can't load font '%s'", fonts[i].name);
293 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
294 CRIT_ERR("can't load font '%s'", "fixed");
295 printf("loaded fixed?\n");
303 /* default config file */
304 static char *current_config;
306 /* set to 1 if you want all text to be in uppercase */
307 static unsigned int stuff_in_upper_case;
309 /* Run how many times? */
310 static unsigned long total_run_times;
313 static int fork_to_background;
315 static int cpu_avg_samples, net_avg_samples;
319 /* Position on the screen */
320 static int text_alignment;
321 static int gap_x, gap_y;
324 static int draw_borders;
325 static int draw_graph_borders;
326 static int stippled_borders;
328 static int draw_shades, draw_outline;
330 static int border_margin, border_width;
332 static long default_fg_color, default_bg_color, default_out_color;
334 /* create own window or draw stuff to root? */
335 static int set_transparent = 0;
338 static int own_window = 0;
339 static int background_colour = 0;
341 /* fixed size/pos is set if wm/user changes them */
342 static int fixed_size = 0, fixed_pos = 0;
345 static int minimum_width, minimum_height;
346 static int maximum_width;
351 static int sensor_device;
354 static long color0, color1, color2, color3, color4, color5, color6, color7,
357 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
358 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
360 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
361 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
363 /* maximum size of individual text buffers, ie $exec buffer size */
364 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
367 #define CODEPAGE_LENGTH 20
369 long iconv_count = 0;
370 char iconv_converting;
371 static iconv_t **iconv_cd = 0;
373 int register_iconv(iconv_t *new_iconv)
376 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
378 iconv_cd = malloc(sizeof(iconv_t *));
381 CRIT_ERR("Out of memory");
383 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
384 if (!iconv_cd[iconv_count]) {
385 CRIT_ERR("Out of memory");
387 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
392 void free_iconv(void)
397 for (i = 0; i < iconv_count; i++) {
399 iconv_close(*iconv_cd[i]);
413 /* no buffers in used memory? */
416 /* pad percentages to decimals? */
417 static int pad_percents = 0;
419 #ifdef TCP_PORT_MONITOR
420 tcp_port_monitor_args_t tcp_port_monitor_args;
423 static char *text = 0;
426 static int total_updates;
429 static int blockdepth = 0;
430 static int if_jumped = 0;
431 static int blockstart[MAX_IF_BLOCK_DEPTH];
433 int check_contains(char *f, char *s)
436 FILE *where = fopen(f, "r");
439 char buf1[256], buf2[256];
441 while (fgets(buf1, 256, where)) {
442 sscanf(buf1, "%255s", buf2);
443 if (strstr(buf2, s)) {
450 ERR("Could not open the file");
456 static inline int calc_text_width(const char *s, int l)
463 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
464 (FcChar8 *) s, l, &gi);
466 XftTextExtents8(display, fonts[selected_font].xftfont,
467 (FcChar8 *) s, l, &gi);
473 return XTextWidth(fonts[selected_font].font, s, l);
478 /* formatted text to render on screen, generated in generate_text(),
479 * drawn in draw_stuff() */
481 static char text_buffer[TEXT_BUFFER_SIZE * 4];
483 /* special stuff in text_buffer */
485 #define SPECIAL_CHAR '\x01'
513 unsigned long first_colour; // for graph gradient
514 unsigned long last_colour;
518 /* create specials array on heap instead of stack with introduction of
520 static struct special_t *specials = NULL;
522 static unsigned int special_count;
525 static unsigned int special_index; /* used when drawing */
528 /* why 256? cause an array of more then 256 doubles seems excessive,
529 * and who needs that kind of precision anyway? */
530 #define MAX_GRAPH_DEPTH 256
532 static struct special_t *new_special(char *buf, enum special_types t)
534 if (special_count >= max_specials) {
535 CRIT_ERR("too many special things in text");
538 buf[0] = SPECIAL_CHAR;
540 specials[special_count].type = t;
541 return &specials[special_count++];
544 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
548 unsigned int count = 0;
549 static char buf[BUFSZ];
550 long orig_pos = ftell(fp);
552 long buf_size = BUFSZ;
553 char *cur_found = NULL;
555 while (count < step) {
556 if (cur_found == NULL) {
557 buf_size = fread(buf, 1, buf_size, fp);
560 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
561 if (cur_found != NULL) {
562 buf_pos = cur_found - buf + 1;
571 ret = ftell(fp) - buf_size + buf_pos - 1;
573 fseek(fp, orig_pos, SEEK_SET);
579 void *memrchr(const void *buffer, char c, size_t n)
581 const unsigned char *p = buffer;
583 for (p += n; n; n--) {
592 long rev_fcharfind(FILE *fp, char val, unsigned int step)
596 unsigned int count = 0;
597 static char buf[BUFSZ];
598 long orig_pos = ftell(fp);
600 long file_pos = orig_pos;
601 long buf_size = BUFSZ;
604 while (count < step) {
606 if (file_pos > BUFSZ) {
607 fseek(fp, file_pos - BUFSZ, SEEK_SET);
610 fseek(fp, 0, SEEK_SET);
612 file_pos = ftell(fp);
613 buf_pos = fread(buf, 1, buf_size, fp);
615 cur_found = memrchr(buf, val, (size_t) buf_pos);
616 if (cur_found != NULL) {
617 buf_pos = cur_found - buf;
626 fseek(fp, orig_pos, SEEK_SET);
628 ret = file_pos + buf_pos;
634 static void new_bar(char *buf, int w, int h, int usage)
636 struct special_t *s = new_special(buf, BAR);
638 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
643 static const char *scan_bar(const char *args, int *w, int *h)
645 /* zero width means all space that is available */
648 /* bar's argument is either height or height,width */
652 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
653 sscanf(args, "%d %n", h, &n);
661 static char *scan_font(const char *args)
671 static void new_font(char *buf, char *args)
674 struct special_t *s = new_special(buf, FONT);
676 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
677 int tmp = selected_font;
679 selected_font = s->font_added = addfont(args);
684 struct special_t *s = new_special(buf, FONT);
685 int tmp = selected_font;
687 selected_font = s->font_added = 0;
693 inline void graph_append(struct special_t *graph, double f)
695 if (!graph->scaled && f > graph->graph_scale) {
696 f = graph->graph_scale;
701 graph->graph_scale = 1;
703 graph->graph[0] = f; /* add new data */
704 /* shift all the data by 1 */
705 for (i = graph->graph_width - 1; i > 0; i--) {
706 graph->graph[i] = graph->graph[i - 1];
707 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
708 /* check if we need to update the scale */
709 graph->graph_scale = graph->graph[i];
714 short colour_depth = 0;
715 void set_up_gradient();
717 /* precalculated: 31/255, and 63/255 */
718 #define CONST_8_TO_5_BITS 0.12156862745098
719 #define CONST_8_TO_6_BITS 0.247058823529412
721 /* adjust color values depending on color depth */
722 static unsigned int adjust_colors(unsigned int color)
726 if (colour_depth == 0) {
729 if (colour_depth == 16) {
730 r = (color & 0xff0000) >> 16;
731 g = (color & 0xff00) >> 8;
733 color = (int) (r * CONST_8_TO_5_BITS) << 11;
734 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
735 color |= (int) (b * CONST_8_TO_5_BITS);
740 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
741 unsigned int second_colour, double i, int scale, int append)
743 struct special_t *s = new_special(buf, GRAPH);
746 if (s->graph == NULL) {
747 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
748 // subtract 2 for the box
749 s->graph_width = s->width /* - 2 */;
751 s->graph_width = MAX_GRAPH_DEPTH - 2;
753 s->graph = malloc(s->graph_width * sizeof(double));
754 memset(s->graph, 0, s->graph_width * sizeof(double));
755 s->graph_scale = 100;
758 s->first_colour = adjust_colors(first_colour);
759 s->last_colour = adjust_colors(second_colour);
766 s->graph_width = s->width - 2; // subtract 2 for rectangle around
771 s->graph_scale = scale;
778 static char *scan_graph(const char *args, int *w, int *h,
779 unsigned int *first_colour, unsigned int *last_colour,
784 /* zero width means all space that is available */
790 /* graph's argument is either height or height,width */
792 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour,
797 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
800 if (sscanf(args, "%63s %d,%d %x %x %i", buf, h, w, first_colour,
801 last_colour, scale) == 6) {
805 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
812 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) == 3) {
816 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
819 if (sscanf(args, "%63s %x %x %i", buf, first_colour, last_colour,
824 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
830 if (sscanf(args, "%d,%d %i", h, w, scale) == 3) {
834 if (sscanf(args, "%d,%d", h, w) == 2) {
837 if (sscanf(args, "%63s %d,%d %i", buf, h, w, scale) < 4) {
839 //TODO: check the return value and throw an error?
840 sscanf(args, "%63s %d,%d", buf, h, w);
846 if (buf[0] == '\0') {
853 static inline void new_hr(char *buf, int a)
855 new_special(buf, HORIZONTAL_LINE)->height = a;
858 static inline void new_stippled_hr(char *buf, int a, int b)
860 struct special_t *s = new_special(buf, STIPPLED_HR);
866 static inline void new_fg(char *buf, long c)
868 new_special(buf, FG)->arg = c;
871 static inline void new_bg(char *buf, long c)
873 new_special(buf, BG)->arg = c;
876 static inline void new_outline(char *buf, long c)
878 new_special(buf, OUTLINE)->arg = c;
881 static inline void new_offset(char *buf, long c)
883 new_special(buf, OFFSET)->arg = c;
886 static inline void new_voffset(char *buf, long c)
888 new_special(buf, VOFFSET)->arg = c;
891 static inline void new_alignr(char *buf, long c)
893 new_special(buf, ALIGNR)->arg = c;
896 static inline void new_alignc(char *buf, long c)
898 new_special(buf, ALIGNC)->arg = c;
901 static inline void new_goto(char *buf, long c)
903 new_special(buf, GOTO)->arg = c;
906 static inline void new_tab(char *buf, int a, int b)
908 struct special_t *s = new_special(buf, TAB);
914 /* quite boring functions */
916 static inline void for_each_line(char *b, void f(char *))
920 for (ps = b, pe = b; *pe; pe++) {
934 static void convert_escapes(char *buf)
936 char *p = buf, *s = buf;
943 } else if (*s == '\\') {
954 /* Prints anything normally printed with snprintf according to the current value
955 * of use_spacer. Actually slightly more flexible than snprintf, as you can
956 * safely specify the destination buffer as one of your inputs. */
957 static int spaced_print(char *buf, int size, char *format, int width,
958 char *func_name, ...) {
961 char *tempbuf = malloc(size * sizeof(char));
963 // Passes the varargs along to vsnprintf
964 va_start(argp, func_name);
965 vsnprintf(tempbuf, size, format, argp);
968 switch (use_spacer) {
970 len = snprintf(buf, size, "%s", tempbuf);
973 len = snprintf(buf, width, "%*s", width - 1, tempbuf);
976 len = snprintf(buf, width, "%-*s", width - 1, tempbuf);
979 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
988 /* converts from bytes to human readable format (k, M, G, T) */
989 static void human_readable(long long num, char *buf, int size, char *func_name)
991 char **suffix = suffixes;
994 static const int WIDTH = 10, SHORT_WIDTH = 8;
998 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1001 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1006 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1012 fnum = num / 1024.0;
1017 if (precision < 0) {
1021 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1022 precision, fnum, **suffix);
1024 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1027 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1032 enum text_object_type {
1043 OBJ_battery_percent,
1045 #endif /* !__OpenBSD__ */
1067 OBJ_diskiograph_read,
1068 OBJ_diskiograph_write,
1103 #if defined(__linux__)
1109 OBJ_i8k_left_fan_status,
1110 OBJ_i8k_right_fan_status,
1111 OBJ_i8k_left_fan_rpm,
1112 OBJ_i8k_right_fan_rpm,
1114 OBJ_i8k_buttons_status,
1124 OBJ_wireless_bitrate,
1126 OBJ_wireless_link_qual,
1127 OBJ_wireless_link_qual_max,
1128 OBJ_wireless_link_qual_perc,
1129 OBJ_wireless_link_bar,
1130 #endif /* __linux__ */
1159 OBJ_running_processes,
1168 OBJ_temp1, /* i2c is used instead in these */
1188 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1189 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1191 OBJ_apm_battery_time,
1192 OBJ_apm_battery_life,
1193 #endif /* __FreeBSD__ __OpenBSD__ */
1195 OBJ_obsd_sensors_temp,
1196 OBJ_obsd_sensors_fan,
1197 OBJ_obsd_sensors_volt,
1200 #endif /* __OpenBSD__ */
1222 OBJ_music_player_interval,
1230 OBJ_xmms2_transport,
1245 OBJ_audacious_status,
1246 OBJ_audacious_title,
1247 OBJ_audacious_length,
1248 OBJ_audacious_length_seconds,
1249 OBJ_audacious_position,
1250 OBJ_audacious_position_seconds,
1251 OBJ_audacious_bitrate,
1252 OBJ_audacious_frequency,
1253 OBJ_audacious_channels,
1254 OBJ_audacious_filename,
1255 OBJ_audacious_playlist_length,
1256 OBJ_audacious_playlist_position,
1270 #ifdef TCP_PORT_MONITOR
1281 OBJ_entropy_poolsize,
1285 struct text_object {
1287 char *s; /* some string */
1288 int i; /* some integer */
1289 long l; /* some other integer */
1290 unsigned int sensor;
1291 struct net_stat *net;
1293 struct diskio_stat *diskio;
1294 unsigned char loadavg[3];
1295 unsigned int cpu_index;
1296 struct mail_s *mail;
1304 char *tz; /* timezone variable */
1305 char *fmt; /* time display formatting */
1343 /* If not -1, a file descriptor to read from when
1344 * logfile is a FIFO. */
1361 timed_thread *p_timed_thread;
1367 #ifdef TCP_PORT_MONITOR
1369 /* starting port to monitor */
1370 in_port_t port_range_begin;
1371 /* ending port to monitor */
1372 in_port_t port_range_end;
1373 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1375 /* 0 to n-1 connections. */
1376 int connection_index;
1394 struct local_mail_s local_mail;
1399 unsigned int c, d, e;
1404 struct text_object_list {
1405 unsigned int text_object_count;
1406 struct text_object *text_objects;
1409 static unsigned int text_object_count;
1410 static struct text_object *text_objects;
1411 static void generate_text_internal(char *p, int p_max_size,
1412 struct text_object *objs, unsigned int object_count,
1413 struct information *cur);
1415 #define MAXDATASIZE 1000
1419 struct mail_s *parse_mail_args(char type, const char *arg)
1421 struct mail_s *mail;
1422 mail = malloc(sizeof(struct mail_s));
1423 memset(mail, 0, sizeof(struct mail_s));
1426 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1429 ERR("Scanning IMAP args failed");
1430 } else if (type == IMAP) {
1431 ERR("Scanning POP3 args failed");
1434 // see if password needs prompting
1435 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1436 int fp = fileno(stdin);
1437 struct termios term;
1439 tcgetattr(fp, &term);
1440 term.c_lflag &= ~ECHO;
1441 tcsetattr(fp, TCSANOW, &term);
1442 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1443 scanf("%128s", mail->pass);
1445 term.c_lflag |= ECHO;
1446 tcsetattr(fp, TCSANOW, &term);
1448 // now we check for optional args
1449 tmp = strstr(arg, "-i ");
1452 sscanf(tmp, "%f", &mail->interval);
1454 mail->interval = 300; // 5 minutes
1456 tmp = strstr(arg, "-p ");
1459 sscanf(tmp, "%lu", &mail->port);
1462 mail->port = 110; // default pop3 port
1463 } else if (type == IMAP) {
1464 mail->port = 143; // default imap port
1468 tmp = strstr(arg, "-f ");
1471 sscanf(tmp, "%s", mail->folder);
1473 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1476 tmp = strstr(arg, "-e ");
1481 if (tmp[0] == '\'') {
1482 len = strstr(tmp + 1, "'") - tmp - 1;
1487 strncpy(mail->command, tmp + 1, len);
1489 mail->command[0] = '\0';
1491 mail->p_timed_thread = NULL;
1495 void *imap_thread(struct mail_s *mail)
1497 int sockfd, numbytes;
1498 char recvbuf[MAXDATASIZE];
1499 char sendbuf[MAXDATASIZE];
1502 unsigned int old_unseen = UINT_MAX;
1503 unsigned int old_messages = UINT_MAX;
1504 struct stat stat_buf;
1506 struct sockaddr_in their_addr; // connector's address information
1508 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1509 herror("gethostbyname");
1514 ERR("Trying IMAP connection again for %s@%s (try %i/5)",
1515 mail->user, mail->host, fail + 1);
1517 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1520 goto next_iteration;
1524 their_addr.sin_family = AF_INET;
1525 // short, network byte order
1526 their_addr.sin_port = htons(mail->port);
1527 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1528 // zero the rest of the struct
1529 memset(&(their_addr.sin_zero), '\0', 8);
1531 if (connect(sockfd, (struct sockaddr *) &their_addr,
1532 sizeof(struct sockaddr)) == -1) {
1535 goto next_iteration;
1537 struct timeval timeout;
1541 timeout.tv_sec = 60; // 60 second timeout i guess
1542 timeout.tv_usec = 0;
1544 FD_SET(sockfd, &fdset);
1545 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1547 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1550 goto next_iteration;
1553 ERR("IMAP connection failed: timeout");
1555 goto next_iteration;
1557 recvbuf[numbytes] = '\0';
1558 if (strstr(recvbuf, "* OK") != recvbuf) {
1559 ERR("IMAP connection failed, probably not an IMAP server");
1561 goto next_iteration;
1563 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1564 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1565 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1566 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1567 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1568 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1571 goto next_iteration;
1573 timeout.tv_sec = 60; // 60 second timeout i guess
1574 timeout.tv_usec = 0;
1576 FD_SET(sockfd, &fdset);
1577 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1579 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1582 goto next_iteration;
1585 recvbuf[numbytes] = '\0';
1586 if (strstr(recvbuf, "a1 OK") == NULL) {
1587 ERR("IMAP server login failed: %s", recvbuf);
1589 goto next_iteration;
1591 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1592 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1593 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1594 MAXDATASIZE - strlen(sendbuf) - 1);
1595 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1598 goto next_iteration;
1600 timeout.tv_sec = 60; // 60 second timeout i guess
1601 timeout.tv_usec = 0;
1603 FD_SET(sockfd, &fdset);
1604 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1606 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1609 goto next_iteration;
1612 recvbuf[numbytes] = '\0';
1613 if (strstr(recvbuf, "a2 OK") == NULL) {
1614 ERR("IMAP status failed: %s", recvbuf);
1616 goto next_iteration;
1618 // now we get the data
1619 reply = strstr(recvbuf, " (MESSAGES ");
1621 *strchr(reply, ')') = '\0';
1622 if (reply == NULL) {
1623 ERR("Error parsing IMAP response: %s", recvbuf);
1625 goto next_iteration;
1627 timed_thread_lock(mail->p_timed_thread);
1628 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1630 timed_thread_unlock(mail->p_timed_thread);
1632 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1633 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1636 goto next_iteration;
1638 timeout.tv_sec = 60; // 60 second timeout i guess
1639 timeout.tv_usec = 0;
1641 FD_SET(sockfd, &fdset);
1642 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1644 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1647 goto next_iteration;
1650 recvbuf[numbytes] = '\0';
1651 if (strstr(recvbuf, "a3 OK") == NULL) {
1652 ERR("IMAP logout failed: %s", recvbuf);
1654 goto next_iteration;
1656 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1657 || (mail->messages > old_messages && mail->unseen > 0))) {
1659 if (system(mail->command) == -1) {
1664 old_unseen = mail->unseen;
1665 old_messages = mail->messages;
1667 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1668 /* if a valid socket, close it */
1671 if (timed_thread_test(mail->p_timed_thread)) {
1672 timed_thread_exit(mail->p_timed_thread);
1680 void *pop3_thread(struct mail_s *mail)
1682 int sockfd, numbytes;
1683 char recvbuf[MAXDATASIZE];
1684 char sendbuf[MAXDATASIZE];
1687 unsigned int old_unseen = UINT_MAX;
1688 struct stat stat_buf;
1690 struct sockaddr_in their_addr; // connector's address information
1692 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1693 herror("gethostbyname");
1698 ERR("Trying POP3 connection again for %s@%s (try %i/5)",
1699 mail->user, mail->host, fail + 1);
1701 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1704 goto next_iteration;
1708 their_addr.sin_family = AF_INET;
1709 // short, network byte order
1710 their_addr.sin_port = htons(mail->port);
1711 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1712 // zero the rest of the struct
1713 memset(&(their_addr.sin_zero), '\0', 8);
1715 if (connect(sockfd, (struct sockaddr *) &their_addr,
1716 sizeof(struct sockaddr)) == -1) {
1719 goto next_iteration;
1721 struct timeval timeout;
1725 timeout.tv_sec = 60; // 60 second timeout i guess
1726 timeout.tv_usec = 0;
1728 FD_SET(sockfd, &fdset);
1729 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1731 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1734 goto next_iteration;
1737 ERR("POP3 connection failed: timeout\n");
1739 goto next_iteration;
1741 recvbuf[numbytes] = '\0';
1742 if (strstr(recvbuf, "+OK ") != recvbuf) {
1743 ERR("POP3 connection failed, probably not a POP3 server");
1745 goto next_iteration;
1747 strncpy(sendbuf, "USER ", MAXDATASIZE);
1748 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1749 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1750 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1751 perror("send USER");
1753 goto next_iteration;
1755 timeout.tv_sec = 60; // 60 second timeout i guess
1756 timeout.tv_usec = 0;
1758 FD_SET(sockfd, &fdset);
1759 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1761 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1762 perror("recv USER");
1764 goto next_iteration;
1767 recvbuf[numbytes] = '\0';
1768 if (strstr(recvbuf, "+OK ") == NULL) {
1769 ERR("POP3 server login failed: %s", recvbuf);
1771 goto next_iteration;
1773 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1774 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1775 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1776 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1777 perror("send PASS");
1779 goto next_iteration;
1781 timeout.tv_sec = 60; // 60 second timeout i guess
1782 timeout.tv_usec = 0;
1784 FD_SET(sockfd, &fdset);
1785 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1787 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1788 perror("recv PASS");
1790 goto next_iteration;
1793 recvbuf[numbytes] = '\0';
1794 if (strstr(recvbuf, "+OK ") == NULL) {
1795 ERR("POP3 server login failed: %s", recvbuf);
1797 goto next_iteration;
1799 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1800 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1801 perror("send STAT");
1803 goto next_iteration;
1805 timeout.tv_sec = 60; // 60 second timeout i guess
1806 timeout.tv_usec = 0;
1808 FD_SET(sockfd, &fdset);
1809 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1811 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1812 perror("recv STAT");
1814 goto next_iteration;
1817 recvbuf[numbytes] = '\0';
1818 if (strstr(recvbuf, "+OK ") == NULL) {
1819 ERR("POP3 status failed: %s", recvbuf);
1821 goto next_iteration;
1823 // now we get the data
1824 reply = recvbuf + 4;
1825 if (reply == NULL) {
1826 ERR("Error parsing POP3 response: %s", recvbuf);
1828 goto next_iteration;
1830 timed_thread_lock(mail->p_timed_thread);
1831 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1832 timed_thread_unlock(mail->p_timed_thread);
1834 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1835 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1836 perror("send QUIT");
1838 goto next_iteration;
1840 timeout.tv_sec = 60; // 60 second timeout i guess
1841 timeout.tv_usec = 0;
1843 FD_SET(sockfd, &fdset);
1844 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1846 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1847 perror("recv QUIT");
1849 goto next_iteration;
1852 recvbuf[numbytes] = '\0';
1853 if (strstr(recvbuf, "+OK") == NULL) {
1854 ERR("POP3 logout failed: %s", recvbuf);
1856 goto next_iteration;
1858 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
1860 if (system(mail->command) == -1) {
1865 old_unseen = mail->unseen;
1867 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1868 /* if a valid socket, close it */
1871 if (timed_thread_test(mail->p_timed_thread)) {
1872 timed_thread_exit(mail->p_timed_thread);
1880 void *threaded_exec(struct text_object *obj)
1883 char *p2 = obj->data.texeci.buffer;
1884 FILE *fp = popen(obj->data.texeci.cmd, "r");
1886 timed_thread_lock(obj->data.texeci.p_timed_thread);
1887 int n2 = fread(p2, 1, text_buffer_size, fp);
1891 if (n2 && p2[n2 - 1] == '\n') {
1895 if (*p2 == '\001') {
1900 timed_thread_unlock(obj->data.texeci.p_timed_thread);
1901 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
1902 timed_thread_exit(obj->data.texeci.p_timed_thread);
1908 static struct text_object *new_text_object_internal()
1910 struct text_object *obj = malloc(sizeof(struct text_object));
1911 memset(obj, 0, sizeof(struct text_object));
1915 static void free_text_objects(unsigned int count, struct text_object *objs)
1919 for (i = 0; i < count; i++) {
1920 switch (objs[i].type) {
1923 close(objs[i].data.i);
1926 close(objs[i].data.i);
1929 close(objs[i].data.sysfs.fd);
1932 close(objs[i].data.sysfs.fd);
1935 close(objs[i].data.sysfs.fd);
1937 #endif /* !__OpenBSD__ */
1939 free(objs[i].data.s);
1942 free(objs[i].data.s);
1945 free(objs[i].data.tztime.tz);
1946 free(objs[i].data.tztime.fmt);
1949 free(objs[i].data.mboxscan.args);
1950 free(objs[i].data.mboxscan.output);
1954 free(objs[i].data.local_mail.box);
1959 case OBJ_imap_unseen:
1960 if (!objs[i].global_mode) {
1961 free(objs[i].data.mail);
1964 case OBJ_imap_messages:
1965 if (!objs[i].global_mode) {
1966 free(objs[i].data.mail);
1972 case OBJ_pop3_unseen:
1973 if (!objs[i].global_mode) {
1974 free(objs[i].data.mail);
1978 if (!objs[i].global_mode) {
1979 free(objs[i].data.mail);
1983 case OBJ_if_existing:
1984 case OBJ_if_mounted:
1985 case OBJ_if_running:
1986 free(objs[i].data.ifblock.s);
1987 free(objs[i].data.ifblock.str);
1990 free(objs[i].data.tail.logfile);
1991 free(objs[i].data.tail.buffer);
1995 free(objs[i].data.s);
1998 free(objs[i].data.s);
2001 free(objs[i].data.s);
2004 free(objs[i].data.s);
2007 free(objs[i].data.s);
2009 /* case OBJ_execibar:
2010 free(objs[i].data.s);
2012 case OBJ_execigraph:
2013 free(objs[i].data.s);
2016 case OBJ_iconv_start:
2021 case OBJ_xmms2_artist:
2022 if (info.xmms2.artist) {
2023 free(info.xmms2.artist);
2024 info.xmms2.artist = 0;
2027 case OBJ_xmms2_album:
2028 if (info.xmms2.album) {
2029 free(info.xmms2.album);
2030 info.xmms2.album = 0;
2033 case OBJ_xmms2_title:
2034 if (info.xmms2.title) {
2035 free(info.xmms2.title);
2036 info.xmms2.title = 0;
2039 case OBJ_xmms2_genre:
2040 if (info.xmms2.genre) {
2041 free(info.xmms2.genre);
2042 info.xmms2.genre = 0;
2045 case OBJ_xmms2_comment:
2046 if (info.xmms2.comment) {
2047 free(info.xmms2.comment);
2048 info.xmms2.comment = 0;
2051 case OBJ_xmms2_decoder:
2052 if (info.xmms2.decoder) {
2053 free(info.xmms2.decoder);
2057 case OBJ_xmms2_transport:
2058 if (info.xmms2.transport) {
2059 free(info.xmms2.transport);
2064 if (info.xmms2.url) {
2065 free(info.xmms2.url);
2069 case OBJ_xmms2_date:
2070 if (info.xmms2.date) {
2071 free(info.xmms2.date);
2072 info.xmms2.date = 0;
2075 case OBJ_xmms2_status:
2076 if (info.xmms2.status) {
2077 free(info.xmms2.status);
2078 info.xmms2.status = 0;
2081 case OBJ_xmms2_smart:
2082 if (info.xmms2.artist) {
2083 free(info.xmms2.artist);
2084 info.xmms2.artist = 0;
2086 if (info.xmms2.title) {
2087 free(info.xmms2.title);
2088 info.xmms2.title = 0;
2090 if (info.xmms2.url) {
2091 free(info.xmms2.url);
2097 case OBJ_bmpx_title:
2098 case OBJ_bmpx_artist:
2099 case OBJ_bmpx_album:
2100 case OBJ_bmpx_track:
2102 case OBJ_bmpx_bitrate:
2107 free(objs[i].data.rss.uri);
2108 free(objs[i].data.rss.action);
2115 free(objs[i].data.s);
2117 case OBJ_battery_time:
2118 free(objs[i].data.s);
2120 #endif /* !__OpenBSD__ */
2122 free(objs[i].data.execi.cmd);
2123 free(objs[i].data.execi.buffer);
2126 free(objs[i].data.texeci.cmd);
2127 free(objs[i].data.texeci.buffer);
2130 if (info.first_process) {
2131 free_all_processes();
2132 info.first_process = NULL;
2136 if (info.first_process) {
2137 free_all_processes();
2138 info.first_process = NULL;
2143 free(objs[i].data.hddtemp.dev);
2144 free(objs[i].data.hddtemp.addr);
2147 case OBJ_entropy_avail:
2148 case OBJ_entropy_poolsize:
2149 case OBJ_entropy_bar:
2155 if (info.mpd.title) {
2156 free(info.mpd.title);
2157 info.mpd.title = NULL;
2159 if (info.mpd.artist) {
2160 free(info.mpd.artist);
2161 info.mpd.artist = NULL;
2163 if (info.mpd.album) {
2164 free(info.mpd.album);
2165 info.mpd.album = NULL;
2167 if (info.mpd.random) {
2168 free(info.mpd.random);
2169 info.mpd.random = NULL;
2171 if (info.mpd.repeat) {
2172 free(info.mpd.repeat);
2173 info.mpd.repeat = NULL;
2175 if (info.mpd.track) {
2176 free(info.mpd.track);
2177 info.mpd.track = NULL;
2179 if (info.mpd.name) {
2180 free(info.mpd.name);
2181 info.mpd.name = NULL;
2183 if (info.mpd.file) {
2184 free(info.mpd.file);
2185 info.mpd.file = NULL;
2187 if (info.mpd.status) {
2188 free(info.mpd.status);
2189 info.mpd.status = NULL;
2192 /* text_objects = NULL;
2193 text_object_count = 0; */
2196 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2201 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2202 *a = mixer_init(buf1);
2203 scan_bar(arg + n, w, h);
2205 *a = mixer_init(NULL);
2206 scan_bar(arg, w, h);
2210 /* construct_text_object() creates a new text_object */
2211 static struct text_object *construct_text_object(const char *s,
2212 const char *arg, unsigned int object_count,
2213 struct text_object *text_objects, long line)
2215 // struct text_object *obj = new_text_object();
2216 struct text_object *obj = new_text_object_internal();
2220 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2221 obj->type = OBJ_##a; need_mask |= (1 << n); {
2222 #define END } } else
2226 obj->type = OBJ_color;
2227 obj->data.l = get_x11_color(s);
2231 OBJ(freq, INFO_FREQ)
2234 obj->data.i = open_acpi_temperature(arg);
2235 END OBJ(acpitempf, 0)
2236 obj->data.i = open_acpi_temperature(arg);
2237 END OBJ(acpiacadapter, 0)
2238 END OBJ(freq, INFO_FREQ)
2239 #endif /* !__OpenBSD__ */
2241 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2242 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2243 obj->data.cpu_index = 1;
2244 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2245 "Displaying the clock for CPU 1."); */
2247 obj->data.cpu_index = atoi(&arg[0]);
2250 END OBJ(freq_g, INFO_FREQ)
2252 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2253 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2254 obj->data.cpu_index = 1;
2255 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2256 "CPUs! Displaying the clock for CPU 1."); */
2258 obj->data.cpu_index = atoi(&arg[0]);
2261 #if defined(__linux__)
2262 END OBJ(voltage_mv, 0)
2264 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2265 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2266 obj->data.cpu_index = 1;
2267 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2268 "CPUs! Displaying voltage for CPU 1."); */
2270 obj->data.cpu_index = atoi(&arg[0]);
2273 END OBJ(voltage_v, 0)
2275 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2276 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2277 obj->data.cpu_index = 1;
2278 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2279 "CPUs! Displaying voltage for CPU 1."); */
2281 obj->data.cpu_index = atoi(&arg[0]);
2286 END OBJ(wireless_essid, INFO_NET)
2288 obj->data.net = get_net_stat(arg);
2290 CRIT_ERR("wireless_essid: needs an argument");
2292 END OBJ(wireless_mode, INFO_NET)
2294 obj->data.net = get_net_stat(arg);
2296 CRIT_ERR("wireless_mode: needs an argument");
2298 END OBJ(wireless_bitrate, INFO_NET)
2300 obj->data.net = get_net_stat(arg);
2302 CRIT_ERR("wireless_bitrate: needs an argument");
2304 END OBJ(wireless_ap, INFO_NET)
2306 obj->data.net = get_net_stat(arg);
2308 CRIT_ERR("wireless_ap: needs an argument");
2310 END OBJ(wireless_link_qual, INFO_NET)
2312 obj->data.net = get_net_stat(arg);
2314 CRIT_ERR("wireless_link_qual: needs an argument");
2316 END OBJ(wireless_link_qual_max, INFO_NET)
2318 obj->data.net = get_net_stat(arg);
2320 CRIT_ERR("wireless_link_qual_max: needs an argument");
2322 END OBJ(wireless_link_qual_perc, INFO_NET)
2324 obj->data.net = get_net_stat(arg);
2326 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2328 END OBJ(wireless_link_bar, INFO_NET)
2330 arg = scan_bar(arg, &obj->a, &obj->b);
2331 obj->data.net = get_net_stat(arg);
2333 CRIT_ERR("wireless_link_bar: needs an argument");
2335 #endif /* HAVE_IWLIB */
2337 #endif /* __linux__ */
2338 END OBJ(freq_dyn, 0)
2339 END OBJ(freq_dyn_g, 0)
2347 sscanf(arg, "%63s", bat);
2349 strcpy(bat, "BAT0");
2351 obj->data.s = strdup(bat);
2352 END OBJ(battery_time, 0)
2356 sscanf(arg, "%63s", bat);
2358 strcpy(bat, "BAT0");
2360 obj->data.s = strdup(bat);
2361 END OBJ(battery_percent, 0)
2365 sscanf(arg, "%63s", bat);
2367 strcpy(bat, "BAT0");
2369 obj->data.s = strdup(bat);
2370 END OBJ(battery_bar, 0)
2374 arg = scan_bar(arg, &obj->a, &obj->b);
2375 sscanf(arg, "%63s", bat);
2377 strcpy(bat, "BAT0");
2379 obj->data.s = strdup(bat);
2380 #endif /* !__OpenBSD__ */
2382 #if defined(__linux__)
2383 END OBJ(i8k_version, INFO_I8K)
2384 END OBJ(i8k_bios, INFO_I8K)
2385 END OBJ(i8k_serial, INFO_I8K)
2386 END OBJ(i8k_cpu_temp, INFO_I8K)
2387 END OBJ(i8k_cpu_tempf, INFO_I8K)
2388 END OBJ(i8k_left_fan_status, INFO_I8K)
2389 END OBJ(i8k_right_fan_status, INFO_I8K)
2390 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2391 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2392 END OBJ(i8k_ac_status, INFO_I8K)
2393 END OBJ(i8k_buttons_status, INFO_I8K)
2395 END OBJ(ibm_temps, 0)
2397 CRIT_ERR("ibm_temps: needs an argument");
2399 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2400 obj->data.sensor = 0;
2401 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2402 "Using 0 (CPU temp sensor).");
2404 obj->data.sensor = atoi(&arg[0]);
2405 END OBJ(ibm_volume, 0)
2406 END OBJ(ibm_brightness, 0)
2407 END OBJ(pb_battery, 0)
2408 if (arg && strcmp(arg, "status") == 0) {
2409 obj->data.i = PB_BATT_STATUS;
2410 } else if (arg && strcmp(arg, "percent") == 0) {
2411 obj->data.i = PB_BATT_PERCENT;
2412 } else if (arg && strcmp(arg, "time") == 0) {
2413 obj->data.i = PB_BATT_TIME;
2415 ERR("pb_battery: needs one argument: status, percent or time");
2420 #endif /* __linux__ */
2421 #if defined(__OpenBSD__)
2422 END OBJ(obsd_sensors_temp, 0)
2424 CRIT_ERR("obsd_sensors_temp: needs an argument");
2426 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2427 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2428 obj->data.sensor = 0;
2429 ERR("Invalid temperature sensor number!");
2431 obj->data.sensor = atoi(&arg[0]);
2432 END OBJ(obsd_sensors_fan, 0)
2434 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2437 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2438 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2439 obj->data.sensor = 0;
2440 ERR("Invalid fan sensor number!");
2442 obj->data.sensor = atoi(&arg[0]);
2443 END OBJ(obsd_sensors_volt, 0)
2445 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2448 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2449 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2450 obj->data.sensor = 0;
2451 ERR("Invalid voltage sensor number!");
2453 obj->data.sensor = atoi(&arg[0]);
2454 END OBJ(obsd_vendor, 0)
2455 END OBJ(obsd_product, 0)
2456 #endif /* __OpenBSD__ */
2457 END OBJ(buffers, INFO_BUFFERS)
2458 END OBJ(cached, INFO_BUFFERS)
2459 END OBJ(cpu, INFO_CPU)
2461 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2462 obj->data.cpu_index = atoi(&arg[3]);
2465 obj->data.cpu_index = 0;
2468 obj->data.cpu_index = 0;
2470 END OBJ(cpubar, INFO_CPU)
2472 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2473 obj->data.cpu_index = atoi(&arg[3]);
2476 obj->data.cpu_index = 0;
2478 scan_bar(arg, &obj->a, &obj->b);
2480 scan_bar(arg, &obj->a, &obj->b);
2481 obj->data.cpu_index = 0;
2483 END OBJ(cpugraph, INFO_CPU)
2484 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2488 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2489 obj->data.cpu_index = atoi(&buf[3]);
2491 obj->data.cpu_index = 0;
2495 END OBJ(diskio, INFO_DISKIO)
2497 obj->data.diskio = prepare_diskio_stat(arg);
2499 obj->data.diskio = NULL;
2501 END OBJ(diskio_read, INFO_DISKIO)
2503 obj->data.diskio = prepare_diskio_stat(arg);
2505 obj->data.diskio = NULL;
2507 END OBJ(diskio_write, INFO_DISKIO)
2509 obj->data.diskio = prepare_diskio_stat(arg);
2511 obj->data.diskio = NULL;
2513 END OBJ(diskiograph, INFO_DISKIO)
2514 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2518 obj->data.diskio = prepare_diskio_stat(buf);
2521 obj->data.diskio = NULL;
2523 END OBJ(diskiograph_read, INFO_DISKIO)
2524 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2528 obj->data.diskio = prepare_diskio_stat(buf);
2531 obj->data.diskio = NULL;
2533 END OBJ(diskiograph_write, INFO_DISKIO)
2534 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2538 obj->data.diskio = prepare_diskio_stat(buf);
2541 obj->data.diskio = NULL;
2545 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2548 obj->data.l = color0;
2550 obj->data.l = color1;
2552 obj->data.l = color2;
2554 obj->data.l = color3;
2556 obj->data.l = color4;
2558 obj->data.l = color5;
2560 obj->data.l = color6;
2562 obj->data.l = color7;
2564 obj->data.l = color8;
2566 obj->data.l = color9;
2568 obj->data.s = scan_font(arg);
2569 END OBJ(downspeed, INFO_NET)
2571 obj->data.net = get_net_stat(arg);
2573 CRIT_ERR("downspeed needs argument");
2575 END OBJ(downspeedf, INFO_NET)
2577 obj->data.net = get_net_stat(arg);
2579 CRIT_ERR("downspeedf needs argument");
2581 END OBJ(downspeedgraph, INFO_NET)
2582 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2586 obj->data.net = get_net_stat(buf);
2591 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2593 blockstart[blockdepth - 1] = object_count;
2594 obj->data.ifblock.pos = object_count + 2;
2596 ERR("$else: no matching $if_*");
2601 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2604 ERR("$endif: no matching $if_*");
2607 obj->data.s = strdup(arg ? arg : "");
2610 obj->data.s = strdup(arg ? arg : "");
2612 obj->data.s = strdup(arg ? arg : "");
2613 END OBJ(execgraph, 0)
2614 obj->data.s = strdup(arg ? arg : "");
2615 END OBJ(execibar, 0)
2618 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2621 ERR("${execibar <interval> command}");
2622 obj->type = OBJ_text;
2623 snprintf(buf, 256, "${%s}", s);
2624 obj->data.s = strdup(buf);
2626 obj->data.execi.cmd = strdup(arg + n);
2628 END OBJ(execigraph, 0)
2631 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2634 ERR("${execigraph <interval> command}");
2635 obj->type = OBJ_text;
2636 snprintf(buf, 256, "${%s}", s);
2637 obj->data.s = strdup(buf);
2639 obj->data.execi.cmd = strdup(arg + n);
2644 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2647 ERR("${execi <interval> command}");
2648 obj->type = OBJ_text;
2649 snprintf(buf, 256, "${%s}", s);
2650 obj->data.s = strdup(buf);
2652 obj->data.execi.cmd = strdup(arg + n);
2653 obj->data.execi.buffer = (char *) calloc(1, text_buffer_size);
2658 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2661 ERR("${texeci <interval> command}");
2662 obj->type = OBJ_text;
2663 snprintf(buf, 256, "${%s}", s);
2664 obj->data.s = strdup(buf);
2666 obj->data.texeci.cmd = strdup(arg + n);
2667 obj->data.texeci.buffer = (char *) calloc(1, text_buffer_size);
2669 obj->data.texeci.p_timed_thread = NULL;
2670 END OBJ(pre_exec, 0)
2671 obj->type = OBJ_text;
2673 FILE *fp = popen(arg, "r");
2677 n = fread(buf, 1, 2048, fp);
2680 if (n && buf[n - 1] == '\n') {
2686 obj->data.s = strdup(buf);
2688 obj->data.s = strdup("");
2691 END OBJ(fs_bar, INFO_FS)
2692 obj->data.fsbar.h = 4;
2693 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2695 while (isspace(*arg)) {
2704 obj->data.fsbar.fs = prepare_fs_stat(arg);
2705 END OBJ(fs_bar_free, INFO_FS)
2706 obj->data.fsbar.h = 4;
2710 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1) {
2716 obj->data.fsbar.fs = prepare_fs_stat(arg);
2717 END OBJ(fs_free, INFO_FS)
2721 obj->data.fs = prepare_fs_stat(arg);
2722 END OBJ(fs_used_perc, INFO_FS)
2726 obj->data.fs = prepare_fs_stat(arg);
2727 END OBJ(fs_free_perc, INFO_FS)
2731 obj->data.fs = prepare_fs_stat(arg);
2732 END OBJ(fs_size, INFO_FS)
2736 obj->data.fs = prepare_fs_stat(arg);
2737 END OBJ(fs_used, INFO_FS)
2741 obj->data.fs = prepare_fs_stat(arg);
2743 obj->data.i = arg ? atoi(arg) : 1;
2745 obj->data.i = arg ? atoi(arg) : 1;
2747 obj->data.i = arg ? atoi(arg) : 1;
2751 ERR("goto needs arguments");
2752 obj->type = OBJ_text;
2753 obj->data.s = strdup("${goto}");
2757 obj->data.i = atoi(arg);
2763 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2764 sscanf(arg, "%d", &b);
2770 obj->data.pair.a = a;
2771 obj->data.pair.b = b;
2774 END OBJ(i2c, INFO_SYSFS)
2775 char buf1[64], buf2[64];
2779 ERR("i2c needs arguments");
2780 obj->type = OBJ_text;
2781 // obj->data.s = strdup("${i2c}");
2785 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2786 /* if scanf couldn't read three values, read type and num and use
2788 sscanf(arg, "%63s %d", buf2, &n);
2789 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
2790 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2791 strncpy(obj->data.sysfs.type, buf2, 63);
2793 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
2794 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2795 strncpy(obj->data.sysfs.type, buf2, 63);
2798 END OBJ(platform, INFO_SYSFS)
2799 char buf1[64], buf2[64];
2803 ERR("platform needs arguments");
2804 obj->type = OBJ_text;
2808 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2809 /* if scanf couldn't read three values, read type and num and use
2811 sscanf(arg, "%63s %d", buf2, &n);
2812 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
2813 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2814 strncpy(obj->data.sysfs.type, buf2, 63);
2816 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
2817 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2818 strncpy(obj->data.sysfs.type, buf2, 63);
2821 END OBJ(hwmon, INFO_SYSFS)
2822 char buf1[64], buf2[64];
2826 ERR("hwmon needs argumanets");
2827 obj->type = OBJ_text;
2831 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2832 /* if scanf couldn't read three values, read type and num and use
2834 sscanf(arg, "%63s %d", buf2, &n);
2835 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
2836 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2837 strncpy(obj->data.sysfs.type, buf2, 63);
2839 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
2840 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2841 strncpy(obj->data.sysfs.type, buf2, 63);
2843 #endif /* !__OpenBSD__ */
2845 END OBJ(top, INFO_TOP)
2850 ERR("top needs arguments");
2851 obj->type = OBJ_text;
2852 // obj->data.s = strdup("${top}");
2855 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2856 if (strcmp(buf, "name") == 0) {
2857 obj->data.top.type = TOP_NAME;
2858 } else if (strcmp(buf, "cpu") == 0) {
2859 obj->data.top.type = TOP_CPU;
2860 } else if (strcmp(buf, "pid") == 0) {
2861 obj->data.top.type = TOP_PID;
2862 } else if (strcmp(buf, "mem") == 0) {
2863 obj->data.top.type = TOP_MEM;
2864 } else if (strcmp(buf, "time") == 0) {
2865 obj->data.top.type = TOP_TIME;
2867 ERR("invalid arg for top");
2870 if (n < 1 || n > 10) {
2871 CRIT_ERR("invalid arg for top");
2874 obj->data.top.num = n - 1;
2878 ERR("invalid args given for top");
2881 END OBJ(top_mem, INFO_TOP)
2886 ERR("top_mem needs arguments");
2887 obj->type = OBJ_text;
2888 obj->data.s = strdup("${top_mem}");
2891 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2892 if (strcmp(buf, "name") == 0) {
2893 obj->data.top.type = TOP_NAME;
2894 } else if (strcmp(buf, "cpu") == 0) {
2895 obj->data.top.type = TOP_CPU;
2896 } else if (strcmp(buf, "pid") == 0) {
2897 obj->data.top.type = TOP_PID;
2898 } else if (strcmp(buf, "mem") == 0) {
2899 obj->data.top.type = TOP_MEM;
2900 } else if (strcmp(buf, "time") == 0) {
2901 obj->data.top.type = TOP_TIME;
2903 ERR("invalid arg for top");
2906 if (n < 1 || n > 10) {
2907 CRIT_ERR("invalid arg for top");
2910 obj->data.top.num = n - 1;
2914 ERR("invalid args given for top");
2917 END OBJ(addr, INFO_NET)
2919 obj->data.net = get_net_stat(arg);
2921 CRIT_ERR("addr needs argument");
2929 ERR("tail needs arguments");
2930 obj->type = OBJ_text;
2931 obj->data.s = strdup("${tail}");
2934 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2935 if (n1 < 1 || n1 > 30) {
2936 CRIT_ERR("invalid arg for tail, number of lines must be "
2937 "between 1 and 30");
2943 obj->data.tail.fd = -1;
2945 if (stat(buf, &st) == 0) {
2946 if (S_ISFIFO(st.st_mode)) {
2947 fd = open(buf, O_RDONLY | O_NONBLOCK);
2950 CRIT_ERR("tail logfile does not exist, or you do "
2951 "not have correct permissions");
2954 obj->data.tail.fd = fd;
2956 fp = fopen(buf, "r");
2960 if (fp || obj->data.tail.fd != -1) {
2961 obj->data.tail.logfile = malloc(text_buffer_size);
2962 strcpy(obj->data.tail.logfile, buf);
2963 obj->data.tail.wantedlines = n1;
2964 obj->data.tail.interval = update_interval * 2;
2966 if (obj->data.tail.fd == -1) {
2971 CRIT_ERR("tail logfile does not exist, or you do not have "
2972 "correct permissions");
2975 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2976 if (n1 < 1 || n1 > 30) {
2977 CRIT_ERR("invalid arg for tail, number of lines must be "
2978 "between 1 and 30");
2980 } else if (n2 < 1 || n2 < update_interval) {
2981 CRIT_ERR("invalid arg for tail, interval must be greater than "
2982 "0 and Conky's interval");
2988 obj->data.tail.fd = -1;
2990 if (stat(buf, &st) == 0) {
2991 if (S_ISFIFO(st.st_mode)) {
2992 fd = open(buf, O_RDONLY | O_NONBLOCK);
2995 CRIT_ERR("tail logfile does not exist, or you do "
2996 "not have correct permissions");
2999 obj->data.tail.fd = fd;
3001 fp = fopen(buf, "r");
3005 if (fp || obj->data.tail.fd != -1) {
3006 obj->data.tail.logfile = malloc(text_buffer_size);
3007 strcpy(obj->data.tail.logfile, buf);
3008 obj->data.tail.wantedlines = n1;
3009 obj->data.tail.interval = n2;
3011 if (obj->data.tail.fd == -1) {
3016 CRIT_ERR("tail logfile does not exist, or you do not have "
3017 "correct permissions");
3021 ERR("invalid args given for tail");
3024 /* asumming all else worked */
3025 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3031 ERR("head needs arguments");
3032 obj->type = OBJ_text;
3033 obj->data.s = strdup("${head}");
3036 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3037 if (n1 < 1 || n1 > 30) {
3038 CRIT_ERR("invalid arg for head, number of lines must be "
3039 "between 1 and 30");
3044 fp = fopen(buf, "r");
3046 obj->data.tail.logfile = malloc(text_buffer_size);
3047 strcpy(obj->data.tail.logfile, buf);
3048 obj->data.tail.wantedlines = n1;
3049 obj->data.tail.interval = update_interval * 2;
3053 CRIT_ERR("head logfile does not exist, or you do not have "
3054 "correct permissions");
3057 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3058 if (n1 < 1 || n1 > 30) {
3059 CRIT_ERR("invalid arg for head, number of lines must be "
3060 "between 1 and 30");
3062 } else if (n2 < 1 || n2 < update_interval) {
3063 CRIT_ERR("invalid arg for head, interval must be greater than "
3064 "0 and Conky's interval");
3069 fp = fopen(buf, "r");
3071 obj->data.tail.logfile = malloc(text_buffer_size);
3072 strcpy(obj->data.tail.logfile, buf);
3073 obj->data.tail.wantedlines = n1;
3074 obj->data.tail.interval = n2;
3078 CRIT_ERR("head logfile does not exist, or you do not have "
3079 "correct permissions");
3083 ERR("invalid args given for head");
3086 /* asumming all else worked */
3087 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3088 END OBJ(loadavg, INFO_LOADAVG)
3089 int a = 1, b = 2, c = 3, r = 3;
3092 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3093 if (r >= 3 && (c < 1 || c > 3)) {
3096 if (r >= 2 && (b < 1 || b > 3)) {
3099 if (r >= 1 && (a < 1 || a > 3)) {
3103 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3104 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3105 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3106 END OBJ(if_empty, 0)
3107 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3108 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3111 ERR("if_empty needs an argument");
3112 obj->data.ifblock.s = 0;
3114 obj->data.ifblock.s = strdup(arg);
3116 blockstart[blockdepth] = object_count;
3117 obj->data.ifblock.pos = object_count + 2;
3119 END OBJ(if_existing, 0)
3120 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3121 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3124 ERR("if_existing needs an argument or two");
3125 obj->data.ifblock.s = NULL;
3126 obj->data.ifblock.str = NULL;
3128 char buf1[256], buf2[256];
3129 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3132 obj->data.ifblock.s = strdup(buf1);
3133 obj->data.ifblock.str = NULL;
3135 obj->data.ifblock.s = strdup(buf1);
3136 obj->data.ifblock.str = strdup(buf2);
3139 blockstart[blockdepth] = object_count;
3140 obj->data.ifblock.pos = object_count + 2;
3142 END OBJ(if_mounted, 0)
3143 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3144 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3147 ERR("if_mounted needs an argument");
3148 obj->data.ifblock.s = 0;
3150 obj->data.ifblock.s = strdup(arg);
3152 blockstart[blockdepth] = object_count;
3153 obj->data.ifblock.pos = object_count + 2;
3155 END OBJ(if_running, 0)
3156 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3157 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3162 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3163 obj->data.ifblock.s = strdup(buf);
3165 ERR("if_running needs an argument");
3166 obj->data.ifblock.s = 0;
3168 blockstart[blockdepth] = object_count;
3169 obj->data.ifblock.pos = object_count + 2;
3175 char box[256], dst[256];
3179 strncpy(box, MAIL_FILE, sizeof(box));
3181 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3183 strncpy(box, arg, sizeof(box));
3187 variable_substitute(box, dst, sizeof(dst));
3188 obj->data.local_mail.box = strdup(dst);
3189 obj->data.local_mail.interval = n1;
3190 END OBJ(mboxscan, 0)
3191 obj->data.mboxscan.args = (char *) malloc(TEXT_BUFFER_SIZE);
3192 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3193 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3194 obj->data.mboxscan.output[0] = 1;
3195 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
3196 END OBJ(mem, INFO_MEM)
3197 END OBJ(memmax, INFO_MEM)
3198 END OBJ(memperc, INFO_MEM)
3199 END OBJ(membar, INFO_MEM)
3200 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3201 END OBJ(memgraph, INFO_MEM)
3202 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3208 END OBJ(mixer, INFO_MIXER)
3209 obj->data.l = mixer_init(arg);
3210 END OBJ(mixerl, INFO_MIXER)
3211 obj->data.l = mixer_init(arg);
3212 END OBJ(mixerr, INFO_MIXER)
3213 obj->data.l = mixer_init(arg);
3214 END OBJ(mixerbar, INFO_MIXER)
3215 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3216 &obj->data.mixerbar.h);
3217 END OBJ(mixerlbar, INFO_MIXER)
3218 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3219 &obj->data.mixerbar.h);
3220 END OBJ(mixerrbar, INFO_MIXER)
3221 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3222 &obj->data.mixerbar.h);
3223 END OBJ(new_mails, 0)
3225 char box[256], dst[256];
3229 strncpy(box, MAIL_FILE, sizeof(box));
3231 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3233 strncpy(box, arg, sizeof(box));
3237 variable_substitute(box, dst, sizeof(dst));
3238 obj->data.local_mail.box = strdup(dst);
3239 obj->data.local_mail.interval = n1;
3240 END OBJ(nodename, 0)
3241 END OBJ(processes, INFO_PROCS)
3242 END OBJ(running_processes, INFO_RUN_PROCS)
3243 END OBJ(shadecolor, 0)
3245 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3247 END OBJ(outlinecolor, 0)
3249 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3251 END OBJ(stippled_hr, 0)
3253 int a = stippled_borders, b = 1;
3256 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3257 sscanf(arg, "%d", &b);
3263 obj->data.pair.a = a;
3264 obj->data.pair.b = b;
3266 END OBJ(swap, INFO_MEM)
3267 END OBJ(swapmax, INFO_MEM)
3268 END OBJ(swapperc, INFO_MEM)
3269 END OBJ(swapbar, INFO_MEM)
3270 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3273 END OBJ(temp1, INFO_SYSFS)
3274 obj->type = OBJ_i2c;
3275 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3276 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3277 END OBJ(temp2, INFO_SYSFS)
3278 obj->type = OBJ_i2c;
3279 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3280 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3283 obj->data.s = strdup(arg ? arg : "%F %T");
3285 obj->data.s = strdup(arg ? arg : "%F %T");
3287 char buf1[256], buf2[256], *fmt, *tz;
3291 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3301 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3302 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3304 END OBJ(iconv_start, 0)
3305 if (iconv_converting) {
3306 CRIT_ERR("You must stop your last iconv conversion before "
3307 "starting another");
3310 char iconv_from[CODEPAGE_LENGTH];
3311 char iconv_to[CODEPAGE_LENGTH];
3313 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3314 CRIT_ERR("Invalid arguments for iconv_start");
3318 new_iconv = iconv_open(iconv_to, iconv_from);
3319 if (new_iconv == (iconv_t) (-1)) {
3320 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3322 obj->a = register_iconv(&new_iconv);
3323 iconv_converting = 1;
3327 CRIT_ERR("Iconv requires arguments");
3329 END OBJ(iconv_stop, 0)
3330 iconv_converting = 0;
3333 END OBJ(totaldown, INFO_NET)
3335 obj->data.net = get_net_stat(arg);
3337 CRIT_ERR("totaldown needs argument");
3339 END OBJ(totalup, INFO_NET)
3340 obj->data.net = get_net_stat(arg);
3342 obj->data.net = get_net_stat(arg);
3344 CRIT_ERR("totalup needs argument");
3348 obj->data.i = arg ? atoi(arg) : 0;
3350 obj->data.i = arg ? atoi(arg) : 0;
3351 END OBJ(upspeed, INFO_NET)
3353 obj->data.net = get_net_stat(arg);
3355 CRIT_ERR("upspeed needs argument");
3357 END OBJ(upspeedf, INFO_NET)
3359 obj->data.net = get_net_stat(arg);
3361 CRIT_ERR("upspeedf needs argument");
3364 END OBJ(upspeedgraph, INFO_NET)
3365 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3369 obj->data.net = get_net_stat(buf);
3372 END OBJ(uptime_short, INFO_UPTIME)
3373 END OBJ(uptime, INFO_UPTIME)
3375 END OBJ(adt746xcpu, 0)
3376 END OBJ(adt746xfan, 0)
3377 #endif /* !__OpenBSD__ */
3378 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3379 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3380 END OBJ(apm_adapter, 0)
3381 END OBJ(apm_battery_life, 0)
3382 END OBJ(apm_battery_time, 0)
3383 #endif /* __FreeBSD__ */
3384 END OBJ(imap_unseen, 0)
3387 obj->data.mail = parse_mail_args(IMAP, arg);
3388 obj->global_mode = 0;
3390 obj->global_mode = 1;
3392 END OBJ(imap_messages, 0)
3395 obj->data.mail = parse_mail_args(IMAP, arg);
3396 obj->global_mode = 0;
3398 obj->global_mode = 1;
3400 END OBJ(pop3_unseen, 0)
3403 obj->data.mail = parse_mail_args(POP3, arg);
3404 obj->global_mode = 0;
3406 obj->global_mode = 1;
3408 END OBJ(pop3_used, 0)
3411 obj->data.mail = parse_mail_args(POP3, arg);
3412 obj->global_mode = 0;
3414 obj->global_mode = 1;
3417 END OBJ(mpd_artist, INFO_MPD)
3418 END OBJ(mpd_title, INFO_MPD)
3420 sscanf(arg, "%d", &info.mpd.max_title_len);
3421 if (info.mpd.max_title_len > 0) {
3422 info.mpd.max_title_len++;
3424 CRIT_ERR("mpd_title: invalid length argument");
3427 info.mpd.max_title_len = 0;
3429 END OBJ(mpd_random, INFO_MPD)
3430 END OBJ(mpd_repeat, INFO_MPD)
3431 END OBJ(mpd_elapsed, INFO_MPD)
3432 END OBJ(mpd_length, INFO_MPD)
3433 END OBJ(mpd_track, INFO_MPD)
3434 END OBJ(mpd_name, INFO_MPD)
3435 END OBJ(mpd_file, INFO_MPD)
3436 END OBJ(mpd_percent, INFO_MPD)
3437 END OBJ(mpd_album, INFO_MPD)
3438 END OBJ(mpd_vol, INFO_MPD)
3439 END OBJ(mpd_bitrate, INFO_MPD)
3440 END OBJ(mpd_status, INFO_MPD)
3441 END OBJ(mpd_bar, INFO_MPD)
3442 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3443 END OBJ(mpd_smart, INFO_MPD)
3446 END OBJ(xmms2_artist, INFO_XMMS2)
3447 END OBJ(xmms2_album, INFO_XMMS2)
3448 END OBJ(xmms2_title, INFO_XMMS2)
3449 END OBJ(xmms2_genre, INFO_XMMS2)
3450 END OBJ(xmms2_comment, INFO_XMMS2)
3451 END OBJ(xmms2_decoder, INFO_XMMS2)
3452 END OBJ(xmms2_transport, INFO_XMMS2)
3453 END OBJ(xmms2_url, INFO_XMMS2)
3454 END OBJ(xmms2_tracknr, INFO_XMMS2)
3455 END OBJ(xmms2_bitrate, INFO_XMMS2)
3456 END OBJ(xmms2_date, INFO_XMMS2)
3457 END OBJ(xmms2_id, INFO_XMMS2)
3458 END OBJ(xmms2_duration, INFO_XMMS2)
3459 END OBJ(xmms2_elapsed, INFO_XMMS2)
3460 END OBJ(xmms2_size, INFO_XMMS2)
3461 END OBJ(xmms2_status, INFO_XMMS2)
3462 END OBJ(xmms2_percent, INFO_XMMS2)
3463 END OBJ(xmms2_bar, INFO_XMMS2)
3464 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3465 END OBJ(xmms2_smart, INFO_XMMS2)
3468 END OBJ(audacious_status, INFO_AUDACIOUS)
3469 END OBJ(audacious_title, INFO_AUDACIOUS)
3471 sscanf(arg, "%d", &info.audacious.max_title_len);
3472 if (info.audacious.max_title_len > 0) {
3473 info.audacious.max_title_len++;
3475 CRIT_ERR("audacious_title: invalid length argument");
3478 END OBJ(audacious_length, INFO_AUDACIOUS)
3479 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3480 END OBJ(audacious_position, INFO_AUDACIOUS)
3481 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3482 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3483 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3484 END OBJ(audacious_channels, INFO_AUDACIOUS)
3485 END OBJ(audacious_filename, INFO_AUDACIOUS)
3486 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3487 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3488 END OBJ(audacious_bar, INFO_AUDACIOUS)
3489 scan_bar(arg, &obj->a, &obj->b);
3492 END OBJ(bmpx_title, INFO_BMPX)
3493 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3494 END OBJ(bmpx_artist, INFO_BMPX)
3495 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3496 END OBJ(bmpx_album, INFO_BMPX)
3497 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3498 END OBJ(bmpx_track, INFO_BMPX)
3499 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3500 END OBJ(bmpx_uri, INFO_BMPX)
3501 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3502 END OBJ(bmpx_bitrate, INFO_BMPX)
3503 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3508 int argc, delay, act_par;
3509 char *uri = (char *) malloc(128 * sizeof(char));
3510 char *action = (char *) malloc(64 * sizeof(char));
3512 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3514 obj->data.rss.uri = uri;
3515 obj->data.rss.delay = delay;
3516 obj->data.rss.action = action;
3517 obj->data.rss.act_par = act_par;
3521 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3527 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3528 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3529 ERR("hddtemp needs arguments");
3530 obj->type = OBJ_text;
3531 obj->data.s = strdup("${hddtemp}");
3535 #ifdef TCP_PORT_MONITOR
3536 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3537 int argc, port_begin, port_end, item, connection_index;
3540 memset(itembuf, 0, sizeof(itembuf));
3541 connection_index = 0;
3542 /* massive argument checking */
3544 CRIT_ERR("tcp_portmon: needs arguments");
3546 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3548 if ((argc != 3) && (argc != 4)) {
3549 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3551 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3552 || (port_end > 65535)) {
3553 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3555 if (port_begin > port_end) {
3556 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3558 if (strncmp(itembuf, "count", 31) == 0) {
3560 } else if (strncmp(itembuf, "rip", 31) == 0) {
3562 } else if (strncmp(itembuf, "rhost", 31) == 0) {
3564 } else if (strncmp(itembuf, "rport", 31) == 0) {
3566 } else if (strncmp(itembuf, "rservice", 31) == 0) {
3567 item = REMOTESERVICE;
3568 } else if (strncmp(itembuf, "lip", 31) == 0) {
3570 } else if (strncmp(itembuf, "lhost", 31) == 0) {
3572 } else if (strncmp(itembuf, "lport", 31) == 0) {
3574 } else if (strncmp(itembuf, "lservice", 31) == 0) {
3575 item = LOCALSERVICE;
3577 CRIT_ERR("tcp_portmon: invalid item specified");
3579 if ((argc == 3) && (item != COUNT)) {
3580 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3583 if ((argc == 4) && (connection_index < 0)) {
3584 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3586 /* ok, args looks good. save the text object data */
3587 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3588 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3589 obj->data.tcp_port_monitor.item = item;
3590 obj->data.tcp_port_monitor.connection_index = connection_index;
3592 /* if the port monitor collection hasn't been created,
3593 * we must create it */
3594 if (!info.p_tcp_port_monitor_collection) {
3595 info.p_tcp_port_monitor_collection =
3596 create_tcp_port_monitor_collection();
3597 if (!info.p_tcp_port_monitor_collection) {
3598 CRIT_ERR("tcp_portmon: unable to create port monitor "
3603 /* if a port monitor for this port does not exist,
3604 * create one and add it to the collection */
3605 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
3606 port_begin, port_end) == NULL) {
3607 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
3608 port_end, &tcp_port_monitor_args);
3611 CRIT_ERR("tcp_portmon: unable to create port monitor");
3613 /* add the newly created monitor to the collection */
3614 if (insert_tcp_port_monitor_into_collection(
3615 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
3616 CRIT_ERR("tcp_portmon: unable to add port monitor to "
3621 END OBJ(entropy_avail, INFO_ENTROPY)
3622 END OBJ(entropy_poolsize, INFO_ENTROPY)
3623 END OBJ(entropy_bar, INFO_ENTROPY)
3624 scan_bar(arg, &obj->a, &obj->b);
3628 ERR("unknown variable %s", s);
3629 obj->type = OBJ_text;
3630 snprintf(buf, 256, "${%s}", s);
3631 obj->data.s = strdup(buf);
3638 static struct text_object *create_plain_text(const char *s)
3640 struct text_object *obj;
3642 if (s == NULL || *s == '\0') {
3646 obj = new_text_object_internal();
3648 obj->type = OBJ_text;
3649 obj->data.s = strdup(s);
3653 static struct text_object_list *extract_variable_text_internal(const char *p)
3655 struct text_object_list *retval;
3656 struct text_object *obj;
3659 retval = malloc(sizeof(struct text_object_list));
3660 memset(retval, 0, sizeof(struct text_object_list));
3661 retval->text_object_count = 0;
3663 long line = text_lines;
3671 obj = create_plain_text(s);
3673 // allocate memory for the object
3674 retval->text_objects = realloc(retval->text_objects,
3675 sizeof(struct text_object) *
3676 (retval->text_object_count + 1));
3677 // assign the new object to the end of the list.
3678 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3679 sizeof(struct text_object));
3691 /* variable is either $foo or ${foo} */
3693 unsigned int brl = 1, brr = 0;
3697 while (*p && brl != brr) {
3712 while (*p && (isalnum((int) *p) || *p == '_')) {
3717 /* copy variable to buffer */
3718 len = (p - s > 255) ? 255 : (p - s);
3719 strncpy(buf, s, len);
3729 /* if variable wasn't found in environment, use some special */
3735 if (strchr(buf, ' ')) {
3736 arg = strchr(buf, ' ');
3739 while (isspace((int) *arg)) {
3747 /* lowercase variable name */
3754 // create new object
3755 obj = construct_text_object(buf, arg,
3756 retval->text_object_count, retval->text_objects, line);
3758 // allocate memory for the object
3759 retval->text_objects = realloc(retval->text_objects,
3760 sizeof(struct text_object) *
3761 (retval->text_object_count + 1));
3762 // assign the new object to the end of the list.
3764 &retval->text_objects[retval->text_object_count++],
3765 obj, sizeof(struct text_object));
3771 obj = create_plain_text("$");
3773 // allocate memory for the object
3774 retval->text_objects = realloc(retval->text_objects,
3775 sizeof(struct text_object) *
3776 (retval->text_object_count + 1));
3777 // assign the new object to the end of the list.
3778 memcpy(&retval->text_objects[retval->text_object_count++],
3779 obj, sizeof(struct text_object));
3786 obj = create_plain_text(s);
3788 // allocate memory for the object
3789 retval->text_objects = realloc(retval->text_objects,
3790 sizeof(struct text_object) * (retval->text_object_count + 1));
3791 // assign the new object to the end of the list.
3792 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3793 sizeof(struct text_object));
3798 ERR("one or more $endif's are missing");
3804 static void extract_variable_text(const char *p)
3806 struct text_object_list *list;
3808 free_text_objects(text_object_count, text_objects);
3809 text_object_count = 0;
3810 text_objects = NULL;
3812 list = extract_variable_text_internal(p);
3813 text_objects = list->text_objects;
3814 text_object_count = list->text_object_count;
3819 void parse_conky_vars(char *text, char *p, struct information *cur)
3821 struct text_object_list *object_list =
3822 extract_variable_text_internal(text);
3824 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects,
3825 object_list->text_object_count, cur);
3829 /* Allows reading from a FIFO (i.e., /dev/xconsole).
3830 * The file descriptor is set to non-blocking which makes this possible.
3832 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
3833 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
3835 #define TAIL_PIPE_BUFSIZE 4096
3839 int fd = obj->data.tail.fd;
3842 char buf[TAIL_PIPE_BUFSIZE];
3843 ssize_t len = read(fd, buf, sizeof(buf));
3847 if (errno != EAGAIN) {
3848 strcpy(obj->data.tail.buffer, "Logfile Read Error");
3849 snprintf(dst, dst_size, "Logfile Read Error");
3853 } else if (len == 0) {
3854 strcpy(obj->data.tail.buffer, "Logfile Empty");
3855 snprintf(dst, dst_size, "Logfile Empty");
3859 for (line_len = 0, i = 0; i < len; i++) {
3863 if (buf[i] == '\n') {
3866 if (obj->data.tail.readlines > 0) {
3871 for (n = 0; obj->data.tail.buffer[n]; n++) {
3872 if (obj->data.tail.buffer[n] == '\n') {
3877 if (++olines < obj->data.tail.wantedlines) {
3883 p = obj->data.tail.buffer + first_line;
3884 pos = n - first_line;
3885 memmove(obj->data.tail.buffer,
3886 obj->data.tail.buffer + first_line, strlen(p));
3887 obj->data.tail.buffer[pos] = 0;
3893 p = buf + last_line;
3895 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
3896 obj->data.tail.buffer[pos + line_len] = 0;
3899 obj->data.tail.readlines = lines;
3907 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
3910 static void generate_text_internal(char *p, int p_max_size,
3911 struct text_object *objs, unsigned int object_count,
3912 struct information *cur)
3917 char buff_in[P_MAX_SIZE] = { 0 };
3918 iconv_converting = 0;
3921 for (i = 0; i < object_count; i++) {
3922 struct text_object *obj = &objs[i];
3924 #define OBJ(a) break; case OBJ_##a:
3926 switch (obj->type) {
3928 ERR("not implemented obj type %d", obj->type);
3931 /* does anyone have decimals in acpi temperature? */
3932 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3933 round_to_int(get_acpi_temperature(obj->data.i)));
3936 /* does anyone have decimals in acpi temperature? */
3937 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3938 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
3941 #endif /* !__OpenBSD__ */
3944 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3945 obj->data.cpu_index);
3951 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3952 obj->data.cpu_index);
3954 /* OpenBSD has no such flag (SUSv2) */
3955 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3956 obj->data.cpu_index);
3960 #if defined(__linux__)
3963 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3964 obj->data.cpu_index);
3969 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3970 obj->data.cpu_index);
3975 OBJ(wireless_essid) {
3976 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3978 OBJ(wireless_mode) {
3979 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3981 OBJ(wireless_bitrate) {
3982 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3985 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3987 OBJ(wireless_link_qual) {
3988 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
3989 obj->data.net->link_qual);
3991 OBJ(wireless_link_qual_max) {
3992 spaced_print(p, p_max_size, "%d", 4,
3993 "wireless_link_qual_max", obj->data.net->link_qual_max);
3995 OBJ(wireless_link_qual_perc) {
3996 if (obj->data.net->link_qual_max > 0) {
3997 spaced_print(p, p_max_size, "%.0f%%", 5,
3998 "wireless_link_qual_perc",
3999 (double) obj->data.net->link_qual /
4000 obj->data.net->link_qual_max * 100);
4002 spaced_print(p, p_max_size, "unk", 5,
4003 "wireless_link_qual_perc");
4006 OBJ(wireless_link_bar) {
4007 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4008 obj->data.net->link_qual_max) * 255.0);
4010 #endif /* HAVE_IWLIB */
4012 #endif /* __linux__ */
4015 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4016 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4020 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4022 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4024 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4029 get_adt746x_cpu(p, p_max_size);
4032 get_adt746x_fan(p, p_max_size);
4035 get_acpi_fan(p, p_max_size);
4037 OBJ(acpiacadapter) {
4038 get_acpi_ac_adapter(p, p_max_size);
4041 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4044 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4046 OBJ(battery_percent) {
4047 snprintf(p, p_max_size, "%d", get_battery_perct(obj->data.s));
4050 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4052 #endif /* __OpenBSD__ */
4055 human_readable(cur->buffers * 1024, p, 255, "buffers");
4058 human_readable(cur->cached * 1024, p, 255, "buffers");
4061 if (obj->data.cpu_index > info.cpu_count) {
4062 printf("obj->data.cpu_index %i info.cpu_count %i",
4063 obj->data.cpu_index, info.cpu_count);
4064 CRIT_ERR("attempting to use more CPUs then you have!");
4066 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4067 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4070 new_bar(p, obj->a, obj->b,
4071 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4074 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4075 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4079 new_fg(p, obj->data.l);
4111 #if defined(__linux__)
4113 snprintf(p, p_max_size, "%s", i8k.version);
4116 snprintf(p, p_max_size, "%s", i8k.bios);
4119 snprintf(p, p_max_size, "%s", i8k.serial);
4122 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4124 OBJ(i8k_cpu_tempf) {
4127 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4128 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4130 OBJ(i8k_left_fan_status) {
4131 int left_fan_status;
4133 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4134 if (left_fan_status == 0) {
4135 snprintf(p, p_max_size, "off");
4137 if (left_fan_status == 1) {
4138 snprintf(p, p_max_size, "low");
4140 if (left_fan_status == 2) {
4141 snprintf(p, p_max_size, "high");
4144 OBJ(i8k_right_fan_status) {
4145 int right_fan_status;
4147 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4148 if (right_fan_status == 0) {
4149 snprintf(p, p_max_size, "off");
4151 if (right_fan_status == 1) {
4152 snprintf(p, p_max_size, "low");
4154 if (right_fan_status == 2) {
4155 snprintf(p, p_max_size, "high");
4158 OBJ(i8k_left_fan_rpm) {
4159 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4161 OBJ(i8k_right_fan_rpm) {
4162 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4164 OBJ(i8k_ac_status) {
4167 sscanf(i8k.ac_status, "%d", &ac_status);
4168 if (ac_status == -1) {
4169 snprintf(p, p_max_size, "disabled (read i8k docs)");
4171 if (ac_status == 0) {
4172 snprintf(p, p_max_size, "off");
4174 if (ac_status == 1) {
4175 snprintf(p, p_max_size, "on");
4178 OBJ(i8k_buttons_status) {
4179 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4182 get_ibm_acpi_fan(p, p_max_size);
4185 get_ibm_acpi_temps();
4186 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4189 get_ibm_acpi_volume(p, p_max_size);
4191 OBJ(ibm_brightness) {
4192 get_ibm_acpi_brightness(p, p_max_size);
4195 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4197 #endif /* __linux__ */
4200 OBJ(obsd_sensors_temp) {
4201 obsd_sensors.device = sensor_device;
4202 update_obsd_sensors();
4203 snprintf(p, p_max_size, "%.1f",
4204 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4206 OBJ(obsd_sensors_fan) {
4207 obsd_sensors.device = sensor_device;
4208 update_obsd_sensors();
4209 snprintf(p, p_max_size, "%d",
4210 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4212 OBJ(obsd_sensors_volt) {
4213 obsd_sensors.device = sensor_device;
4214 update_obsd_sensors();
4215 snprintf(p, p_max_size, "%.2f",
4216 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4219 get_obsd_vendor(p, p_max_size);
4222 get_obsd_product(p, p_max_size);
4224 #endif /* __OpenBSD__ */
4228 new_font(p, obj->data.s);
4231 /* TODO: move this correction from kB to kB/s elsewhere
4232 * (or get rid of it??) */
4234 if (obj->data.diskio) {
4236 (obj->data.diskio->current / update_interval) * 1024LL,
4237 p, p_max_size, "diskio");
4239 human_readable(diskio_value * 1024LL, p, p_max_size,
4244 if (obj->data.diskio) {
4245 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4248 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4253 if (obj->data.diskio) {
4254 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4257 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4262 if (obj->data.diskio) {
4263 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4264 obj->data.diskio->current, obj->e, 1);
4266 new_graph(p, obj->a, obj->b, obj->c, obj->d, diskio_value,
4270 OBJ(diskiograph_read) {
4271 if (obj->data.diskio) {
4272 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4273 obj->data.diskio->current_read, obj->e, 1);
4275 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4276 diskio_read_value, obj->e, 1);
4279 OBJ(diskiograph_write) {
4280 if (obj->data.diskio) {
4281 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4282 obj->data.diskio->current_write, obj->e, 1);
4284 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4285 diskio_write_value, obj->e, 1);
4289 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4290 round_to_int(obj->data.net->recv_speed / 1024));
4293 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4294 obj->data.net->recv_speed / 1024.0);
4296 OBJ(downspeedgraph) {
4297 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4298 obj->data.net->recv_speed / 1024.0, obj->e, 1);
4302 i = obj->data.ifblock.pos - 1;
4312 snprintf(p, p_max_size, "%u.%u.%u.%u",
4313 obj->data.net->addr.sa_data[2] & 255,
4314 obj->data.net->addr.sa_data[3] & 255,
4315 obj->data.net->addr.sa_data[4] & 255,
4316 obj->data.net->addr.sa_data[5] & 255);
4319 #if defined(IMLIB2) && defined(X11)
4324 Imlib_Image image, buffer;
4326 image = imlib_load_image(obj->data.s);
4327 imlib_context_set_image(image);
4331 w = imlib_image_get_width();
4332 h = imlib_image_get_height();
4333 buffer = imlib_create_image(w, h);
4334 imlib_context_set_display(display);
4335 imlib_context_set_drawable(window.drawable);
4336 imlib_context_set_colormap(DefaultColormap(display,
4338 imlib_context_set_visual(DefaultVisual(display,
4340 imlib_context_set_image(buffer);
4341 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4342 text_start_x, text_start_y, w, h);
4343 imlib_render_image_on_drawable(text_start_x,
4346 imlib_context_set_image(image);
4354 FILE *fp = popen(obj->data.s, "r");
4355 int length = fread(p, 1, p_max_size, fp);
4358 /* output[length] = '\0';
4359 if (length > 0 && output[length - 1] == '\n') {
4360 output[length - 1] = '\0';
4363 if (length > 0 && p[length - 1] == '\n') {
4364 p[length - 1] = '\0';
4366 // parse_conky_vars(output, p, cur);
4370 FILE *fp = popen(obj->data.s, "r");
4371 int n2 = fread(p, 1, p_max_size, fp);
4375 if (n2 && p[n2 - 1] == '\n') {
4380 if (*p2 == '\001') {
4387 if (sscanf(p, "%lf", &barnum) == 0) {
4388 ERR("reading execbar value failed (perhaps it's not the "
4389 "correct format?)");
4391 if (barnum > 100 || barnum < 0) {
4392 ERR("your execbar value is not between 0 and 100, "
4393 "therefore it will be ignored");
4395 barnum = barnum / 100.0;
4396 new_bar(p, 0, 4, (int) (barnum * 255.0));
4401 FILE *fp = popen(obj->data.s, "r");
4402 int n2 = fread(p, 1, p_max_size, fp);
4406 if (n2 && p[n2 - 1] == '\n') {
4410 if (*p2 == '\001') {
4417 if (sscanf(p, "%lf", &barnum) == 0) {
4418 ERR("reading execgraph value failed (perhaps it's not the "
4419 "correct format?)");
4421 if (barnum > 100 || barnum < 0) {
4422 ERR("your execgraph value is not between 0 and 100, "
4423 "therefore it will be ignored");
4425 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum),
4430 if (current_update_time - obj->data.execi.last_update
4431 < obj->data.execi.interval) {
4432 new_bar(p, 0, 4, (int) obj->f);
4435 FILE *fp = popen(obj->data.execi.cmd, "r");
4436 int n2 = fread(p, 1, p_max_size, fp);
4440 if (n2 && p[n2 - 1] == '\n') {
4445 if (*p2 == '\001') {
4452 if (sscanf(p, "%f", &barnum) == 0) {
4453 ERR("reading execibar value failed (perhaps it's not "
4454 "the correct format?)");
4456 if (barnum > 100 || barnum < 0) {
4457 ERR("your execibar value is not between 0 and 100, "
4458 "therefore it will be ignored");
4460 obj->f = 255 * barnum / 100.0;
4461 new_bar(p, 0, 4, (int) obj->f);
4463 obj->data.execi.last_update = current_update_time;
4467 if (current_update_time - obj->data.execi.last_update
4468 < obj->data.execi.interval) {
4469 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4472 FILE *fp = popen(obj->data.execi.cmd, "r");
4473 int n2 = fread(p, 1, p_max_size, fp);
4477 if (n2 && p[n2 - 1] == '\n') {
4482 if (*p2 == '\001') {
4489 if (sscanf(p, "%f", &barnum) == 0) {
4490 ERR("reading execigraph value failed (perhaps it's not "
4491 "the correct format?)");
4493 if (barnum > 100 || barnum < 0) {
4494 ERR("your execigraph value is not between 0 and 100, "
4495 "therefore it will be ignored");
4498 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
4501 obj->data.execi.last_update = current_update_time;
4505 if (current_update_time - obj->data.execi.last_update
4506 < obj->data.execi.interval
4507 || obj->data.execi.interval == 0) {
4508 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4510 char *output = obj->data.execi.buffer;
4511 FILE *fp = popen(obj->data.execi.cmd, "r");
4513 // int length = fread(output, 1, text_buffer_size, fp);
4514 int length = fread(output, 1, text_buffer_size, fp);
4517 output[length] = '\0';
4518 if (length > 0 && output[length - 1] == '\n') {
4519 output[length - 1] = '\0';
4521 obj->data.execi.last_update = current_update_time;
4522 snprintf(p, p_max_size, "%s", output);
4524 // parse_conky_vars(output, p, cur);
4527 if (!obj->data.texeci.p_timed_thread) {
4528 obj->data.texeci.p_timed_thread =
4529 timed_thread_create((void *) threaded_exec,
4530 (void *) obj, obj->data.texeci.interval * 1000000);
4531 if (!obj->data.texeci.p_timed_thread) {
4532 ERR("Error creating texeci timed thread");
4534 timed_thread_register(obj->data.texeci.p_timed_thread,
4535 &obj->data.texeci.p_timed_thread);
4536 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4537 ERR("Error running texeci timed thread");
4540 timed_thread_lock(obj->data.texeci.p_timed_thread);
4541 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4542 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4544 #endif /* HAVE_POPEN */
4546 if (obj->global_mode && info.mail) {
4547 // this means we use info
4548 if (!info.mail->p_timed_thread) {
4549 info.mail->p_timed_thread =
4550 timed_thread_create((void *) imap_thread,
4551 (void *) info.mail, info.mail->interval * 1000000);
4552 if (!info.mail->p_timed_thread) {
4553 ERR("Error creating imap timed thread");
4555 timed_thread_register(info.mail->p_timed_thread,
4556 &info.mail->p_timed_thread);
4557 if (timed_thread_run(info.mail->p_timed_thread)) {
4558 ERR("Error running imap timed thread");
4561 timed_thread_lock(info.mail->p_timed_thread);
4562 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4563 timed_thread_unlock(info.mail->p_timed_thread);
4564 } else if (obj->data.mail) {
4565 // this means we use obj
4566 if (!obj->data.mail->p_timed_thread) {
4567 obj->data.mail->p_timed_thread =
4568 timed_thread_create((void *) imap_thread,
4569 (void *) obj->data.mail,
4570 obj->data.mail->interval * 1000000);
4571 if (!obj->data.mail->p_timed_thread) {
4572 ERR("Error creating imap timed thread");
4574 timed_thread_register(obj->data.mail->p_timed_thread,
4575 &obj->data.mail->p_timed_thread);
4576 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4577 ERR("Error running imap timed thread");
4580 timed_thread_lock(obj->data.mail->p_timed_thread);
4581 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4582 timed_thread_unlock(obj->data.mail->p_timed_thread);
4583 } else if (!obj->a) {
4584 // something is wrong, warn once then stop
4585 ERR("Theres a problem with your imap_unseen settings. "
4586 "Check that the global IMAP settings are defined "
4587 "properly (line %li).", obj->line);
4591 OBJ(imap_messages) {
4592 if (obj->global_mode && info.mail) {
4593 // this means we use info
4594 if (!info.mail->p_timed_thread) {
4595 info.mail->p_timed_thread =
4596 timed_thread_create((void *) imap_thread,
4597 (void *) info.mail, info.mail->interval * 1000000);
4598 if (!info.mail->p_timed_thread) {
4599 ERR("Error creating imap timed thread");
4601 timed_thread_register(info.mail->p_timed_thread,
4602 &info.mail->p_timed_thread);
4603 if (timed_thread_run(info.mail->p_timed_thread)) {
4604 ERR("Error running imap timed thread");
4607 timed_thread_lock(info.mail->p_timed_thread);
4608 snprintf(p, p_max_size, "%lu", info.mail->messages);
4609 timed_thread_unlock(info.mail->p_timed_thread);
4610 } else if (obj->data.mail) {
4611 // this means we use obj
4612 if (!obj->data.mail->p_timed_thread) {
4613 obj->data.mail->p_timed_thread =
4614 timed_thread_create((void *) imap_thread,
4615 (void *) obj->data.mail,
4616 obj->data.mail->interval * 1000000);
4617 if (!obj->data.mail->p_timed_thread) {
4618 ERR("Error creating imap timed thread");
4620 timed_thread_register(obj->data.mail->p_timed_thread,
4621 &obj->data.mail->p_timed_thread);
4622 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4623 ERR("Error runninging imap timed thread");
4626 timed_thread_lock(obj->data.mail->p_timed_thread);
4627 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4628 timed_thread_lock(obj->data.mail->p_timed_thread);
4629 } else if (!obj->a) {
4630 // something is wrong, warn once then stop
4631 ERR("Theres a problem with your imap_messages settings. "
4632 "Check that the global IMAP settings are defined "
4633 "properly (line %li).", obj->line);
4638 if (obj->global_mode && info.mail) {
4639 // this means we use info
4640 if (!info.mail->p_timed_thread) {
4641 info.mail->p_timed_thread =
4642 timed_thread_create((void *) pop3_thread,
4643 (void *) info.mail, info.mail->interval * 1000000);
4644 if (!info.mail->p_timed_thread) {
4645 ERR("Error creating pop3 timed thread");
4647 timed_thread_register(info.mail->p_timed_thread,
4648 &info.mail->p_timed_thread);
4649 if (timed_thread_run(info.mail->p_timed_thread)) {
4650 ERR("Error running pop3 timed thread");
4653 timed_thread_lock(info.mail->p_timed_thread);
4654 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4655 timed_thread_unlock(info.mail->p_timed_thread);
4656 } else if (obj->data.mail) {
4657 // this means we use obj
4658 if (!obj->data.mail->p_timed_thread) {
4659 obj->data.mail->p_timed_thread =
4660 timed_thread_create((void *) pop3_thread,
4661 (void *) obj->data.mail,
4662 obj->data.mail->interval * 1000000);
4663 if (!obj->data.mail->p_timed_thread) {
4664 ERR("Error creating pop3 timed thread");
4666 timed_thread_register(obj->data.mail->p_timed_thread,
4667 &obj->data.mail->p_timed_thread);
4668 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4669 ERR("Error running pop3 timed thread");
4672 timed_thread_lock(obj->data.mail->p_timed_thread);
4673 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4674 timed_thread_unlock(obj->data.mail->p_timed_thread);
4675 } else if (!obj->a) {
4676 // something is wrong, warn once then stop
4677 ERR("Theres a problem with your pop3_unseen settings. "
4678 "Check that the global POP3 settings are defined "
4679 "properly (line %li).", obj->line);
4684 if (obj->global_mode && info.mail) {
4685 // this means we use info
4686 if (!info.mail->p_timed_thread) {
4687 info.mail->p_timed_thread =
4688 timed_thread_create((void *) pop3_thread,
4689 (void *) info.mail, info.mail->interval * 1000000);
4690 if (!info.mail->p_timed_thread) {
4691 ERR("Error creating pop3 timed thread");
4693 timed_thread_register(info.mail->p_timed_thread,
4694 &info.mail->p_timed_thread);
4695 if (timed_thread_run(info.mail->p_timed_thread)) {
4696 ERR("Error running pop3 timed thread");
4699 timed_thread_lock(info.mail->p_timed_thread);
4700 snprintf(p, p_max_size, "%.1f",
4701 info.mail->used / 1024.0 / 1024.0);
4702 timed_thread_unlock(info.mail->p_timed_thread);
4703 } else if (obj->data.mail) {
4704 // this means we use obj
4705 if (!obj->data.mail->p_timed_thread) {
4706 obj->data.mail->p_timed_thread =
4707 timed_thread_create((void *) pop3_thread,
4708 (void *) obj->data.mail,
4709 obj->data.mail->interval * 1000000);
4710 if (!obj->data.mail->p_timed_thread) {
4711 ERR("Error creating pop3 timed thread");
4713 timed_thread_register(obj->data.mail->p_timed_thread,
4714 &obj->data.mail->p_timed_thread);
4715 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4716 ERR("Error running pop3 timed thread");
4719 timed_thread_lock(obj->data.mail->p_timed_thread);
4720 snprintf(p, p_max_size, "%.1f",
4721 obj->data.mail->used / 1024.0 / 1024.0);
4722 timed_thread_unlock(obj->data.mail->p_timed_thread);
4723 } else if (!obj->a) {
4724 // something is wrong, warn once then stop
4725 ERR("Theres a problem with your pop3_used settings. "
4726 "Check that the global POP3 settings are defined "
4727 "properly (line %li).", obj->line);
4732 if (obj->data.fs != NULL) {
4733 if (obj->data.fs->size == 0) {
4734 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4736 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4737 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4738 obj->data.fs->size));
4743 if (obj->data.fs != NULL) {
4744 human_readable(obj->data.fs->avail, p, 255, "fs_free");
4748 if (obj->data.fs != NULL) {
4749 if (obj->data.fs->size) {
4750 snprintf(p, p_max_size, "%*d", pad_percents,
4751 (int) ((obj->data.fs->avail * 100) /
4752 obj->data.fs->size));
4754 snprintf(p, p_max_size, "0");
4759 if (obj->data.fs != NULL) {
4760 human_readable(obj->data.fs->size, p, 255, "fs_size");
4764 if (obj->data.fs != NULL) {
4765 human_readable(obj->data.fs->size - (obj->data.fs->free
4766 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
4771 if (obj->data.fs != NULL) {
4772 if (obj->data.fs->size == 0) {
4773 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4775 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4776 (int) (obj->data.fsbar.fs->avail * 255 /
4777 obj->data.fs->size));
4782 if (obj->data.fs != NULL) {
4783 if (obj->data.fs->size) {
4784 snprintf(p, 4, "%d",
4785 100 - ((int) ((obj->data.fs->avail * 100) /
4786 obj->data.fs->size)));
4788 snprintf(p, p_max_size, "0");
4793 float *v = info.loadavg;
4795 if (obj->data.loadavg[2]) {
4796 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4797 v[obj->data.loadavg[0] - 1],
4798 v[obj->data.loadavg[1] - 1],
4799 v[obj->data.loadavg[2] - 1]);
4800 } else if (obj->data.loadavg[1]) {
4801 snprintf(p, p_max_size, "%.2f %.2f",
4802 v[obj->data.loadavg[0] - 1],
4803 v[obj->data.loadavg[1] - 1]);
4804 } else if (obj->data.loadavg[0]) {
4805 snprintf(p, p_max_size, "%.2f",
4806 v[obj->data.loadavg[0] - 1]);
4810 new_goto(p, obj->data.i);
4813 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4816 new_hr(p, obj->data.i);
4820 PRSS *data = get_rss_info(obj->data.rss.uri,
4821 obj->data.rss.delay);
4825 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4827 if (!strcmp(obj->data.rss.action, "feed_title")) {
4829 // remove trailing new line if one exists
4830 if (str[strlen(str) - 1] == '\n') {
4831 str[strlen(str) - 1] = 0;
4833 snprintf(p, p_max_size, "%s", str);
4834 } else if (!strcmp(obj->data.rss.action, "item_title")) {
4835 if (obj->data.rss.act_par < data->item_count) {
4836 str = data->items[obj->data.rss.act_par].title;
4837 // remove trailing new line if one exists
4838 if (str[strlen(str) - 1] == '\n') {
4839 str[strlen(str) - 1] = 0;
4841 snprintf(p, p_max_size, "%s", str);
4843 } else if (!strcmp(obj->data.rss.action, "item_desc")) {
4844 if (obj->data.rss.act_par < data->item_count) {
4846 data->items[obj->data.rss.act_par].description;
4847 // remove trailing new line if one exists
4848 if (str[strlen(str) - 1] == '\n') {
4849 str[strlen(str) - 1] = 0;
4851 snprintf(p, p_max_size, "%s", str);
4853 } else if (!strcmp(obj->data.rss.action, "item_titles")) {
4854 if (data->item_count > 0) {
4860 if (obj->data.rss.act_par > data->item_count) {
4861 show = data->item_count;
4863 show = obj->data.rss.act_par;
4865 for (itmp = 0; itmp < show; itmp++) {
4866 PRSS_Item *item = &data->items[itmp];
4870 // don't add new line before first item
4872 strncat(p, "\n", p_max_size);
4874 /* remove trailing new line if one exists,
4875 * we have our own */
4876 if (str[strlen(str) - 1] == '\n') {
4877 str[strlen(str) - 1] = 0;
4879 strncat(p, str, p_max_size);
4892 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4893 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4895 snprintf(p, p_max_size, "N/A");
4896 } else if (unit == '*') {
4897 snprintf(p, p_max_size, "%s", temp);
4899 snprintf(p, p_max_size, "%s°%c", temp, unit);
4904 new_offset(p, obj->data.i);
4907 new_voffset(p, obj->data.i);
4913 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4914 obj->data.sysfs.devtype, obj->data.sysfs.type);
4916 if (r >= 100.0 || r == 0) {
4917 snprintf(p, p_max_size, "%d", (int) r);
4919 snprintf(p, p_max_size, "%.1f", r);
4925 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4926 obj->data.sysfs.devtype, obj->data.sysfs.type);
4928 if (r >= 100.0 || r == 0) {
4929 snprintf(p, p_max_size, "%d", (int) r);
4931 snprintf(p, p_max_size, "%.1f", r);
4937 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4938 obj->data.sysfs.devtype, obj->data.sysfs.type);
4940 if (r >= 100.0 || r == 0) {
4941 snprintf(p, p_max_size, "%d", (int) r);
4943 snprintf(p, p_max_size, "%.1f", r);
4946 #endif /* !__OpenBSD__ */
4948 new_alignr(p, obj->data.i);
4951 new_alignc(p, obj->data.i);
4954 struct information *my_info =
4955 malloc(sizeof(struct information));
4957 memcpy(my_info, cur, sizeof(struct information));
4958 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4959 if (strlen(p) != 0) {
4960 i = obj->data.ifblock.pos;
4971 if ((obj->data.ifblock.s)
4972 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
4973 i = obj->data.ifblock.pos;
4976 if (obj->data.ifblock.str) {
4977 if (!check_contains(obj->data.ifblock.s,
4978 obj->data.ifblock.str)) {
4979 i = obj->data.ifblock.pos;
4990 if ((obj->data.ifblock.s)
4991 && (!check_mount(obj->data.ifblock.s))) {
4992 i = obj->data.ifblock.pos;
4999 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5000 i = obj->data.ifblock.pos;
5007 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5010 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5015 human_readable(cur->mem * 1024, p, 255, "mem");
5018 human_readable(cur->memmax * 1024, p, 255, "memmax");
5022 spaced_print(p, p_max_size, "%*Lu", 4, "memperc",
5023 pad_percents, cur->mem * 100 / cur->memmax);
5027 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5028 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5031 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5032 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5038 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5041 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5044 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5047 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5048 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5051 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5052 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5055 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5056 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5061 update_mail_count(&obj->data.local_mail);
5062 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5065 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5067 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5070 update_mail_count(&obj->data.local_mail);
5071 snprintf(p, p_max_size, "%d",
5072 obj->data.local_mail.new_mail_count);
5075 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5078 new_outline(p, obj->data.l);
5081 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5083 OBJ(running_processes) {
5084 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5087 snprintf(p, p_max_size, "%s", obj->data.s);
5090 new_bg(p, obj->data.l);
5093 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5096 human_readable(cur->swap * 1024, p, 255, "swap");
5099 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5102 if (cur->swapmax == 0) {
5103 strncpy(p, "No swap", p_max_size);
5105 spaced_print(p, p_max_size, "%*Lu", 4, "swapperc",
5106 pad_percents, cur->swap * 100 / cur->swapmax);
5110 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5111 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5114 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5117 time_t t = time(NULL);
5118 struct tm *tm = localtime(&t);
5120 setlocale(LC_TIME, "");
5121 strftime(p, p_max_size, obj->data.s, tm);
5124 time_t t = time(NULL);
5125 struct tm *tm = gmtime(&t);
5127 strftime(p, p_max_size, obj->data.s, tm);
5132 if (obj->data.tztime.tz) {
5133 oldTZ = getenv("TZ");
5134 setenv("TZ", obj->data.tztime.tz, 1);
5137 time_t t = time(NULL);
5138 struct tm *tm = localtime(&t);
5140 setlocale(LC_TIME, "");
5141 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5143 setenv("TZ", oldTZ, 1);
5148 // Needless to free oldTZ since getenv gives ptr to static data
5151 human_readable(obj->data.net->recv, p, 255, "totaldown");
5154 human_readable(obj->data.net->trans, p, 255, "totalup");
5157 snprintf(p, p_max_size, "%d", total_updates);
5160 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5161 round_to_int(obj->data.net->trans_speed / 1024));
5164 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5165 obj->data.net->trans_speed / 1024.0);
5168 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5169 obj->data.net->trans_speed / 1024.0, obj->e, 1);
5172 format_seconds_short(p, p_max_size, (int) cur->uptime);
5175 format_seconds(p, p_max_size, (int) cur->uptime);
5178 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5179 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5183 msg = get_apm_adapter();
5184 snprintf(p, p_max_size, "%s", msg);
5187 OBJ(apm_battery_life) {
5190 msg = get_apm_battery_life();
5191 snprintf(p, p_max_size, "%s", msg);
5194 OBJ(apm_battery_time) {
5197 msg = get_apm_battery_time();
5198 snprintf(p, p_max_size, "%s", msg);
5201 #endif /* __FreeBSD__ __OpenBSD__ */
5205 snprintf(p, cur->mpd.max_title_len > 0
5206 ? cur->mpd.max_title_len : p_max_size, "%s",
5210 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5213 snprintf(p, p_max_size, "%s", cur->mpd.album);
5216 snprintf(p, p_max_size, "%s", cur->mpd.random);
5219 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5222 snprintf(p, p_max_size, "%s", cur->mpd.track);
5225 snprintf(p, p_max_size, "%s", cur->mpd.name);
5228 snprintf(p, p_max_size, "%s", cur->mpd.file);
5231 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5234 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5237 snprintf(p, p_max_size, "%s", cur->mpd.status);
5240 int days = 0, hours = 0, minutes = 0, seconds = 0;
5241 int tmp = cur->mpd.elapsed;
5243 while (tmp >= 86400) {
5247 while (tmp >= 3600) {
5257 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5258 hours, minutes, seconds);
5259 } else if (hours > 0) {
5260 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5263 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5267 int days = 0, hours = 0, minutes = 0, seconds = 0;
5268 int tmp = cur->mpd.length;
5270 while (tmp >= 86400) {
5274 while (tmp >= 3600) {
5284 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5285 hours, minutes, seconds);
5286 } else if (hours > 0) {
5287 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5290 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5294 snprintf(p, p_max_size, "%2.0f", cur->mpd.progress * 100);
5297 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5298 (int) (cur->mpd.progress * 255.0f));
5301 memset(p, 0, p_max_size);
5302 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5303 && *cur->mpd.title) {
5304 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5306 } else if (cur->mpd.title && *cur->mpd.title) {
5307 snprintf(p, p_max_size, "%s", cur->mpd.title);
5308 } else if (cur->mpd.artist && *cur->mpd.artist) {
5309 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5310 } else if (cur->mpd.file && *cur->mpd.file) {
5311 snprintf(p, p_max_size, "%s", cur->mpd.file);
5320 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5323 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5326 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5329 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5331 OBJ(xmms2_comment) {
5332 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5334 OBJ(xmms2_decoder) {
5335 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
5337 OBJ(xmms2_transport) {
5338 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
5341 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5344 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5347 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5349 OBJ(xmms2_tracknr) {
5350 if (cur->xmms2.tracknr != -1) {
5351 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5354 OBJ(xmms2_bitrate) {
5355 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5358 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5361 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5363 OBJ(xmms2_elapsed) {
5364 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5365 (cur->xmms2.elapsed / 1000) % 60);
5367 OBJ(xmms2_duration) {
5368 snprintf(p, p_max_size, "%02d:%02d",
5369 cur->xmms2.duration / 60000,
5370 (cur->xmms2.duration / 1000) % 60);
5372 OBJ(xmms2_percent) {
5373 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5376 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5377 (int) (cur->xmms2.progress * 255.0f));
5380 if (strlen(cur->xmms2.title) < 2
5381 && strlen(cur->xmms2.title) < 2) {
5382 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5384 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5390 OBJ(audacious_status) {
5391 snprintf(p, p_max_size, "%s",
5392 cur->audacious.items[AUDACIOUS_STATUS]);
5394 OBJ(audacious_title) {
5395 snprintf(p, cur->audacious.max_title_len > 0
5396 ? cur->audacious.max_title_len : p_max_size, "%s",
5397 cur->audacious.items[AUDACIOUS_TITLE]);
5399 OBJ(audacious_length) {
5400 snprintf(p, p_max_size, "%s",
5401 cur->audacious.items[AUDACIOUS_LENGTH]);
5403 OBJ(audacious_length_seconds) {
5404 snprintf(p, p_max_size, "%s",
5405 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5407 OBJ(audacious_position) {
5408 snprintf(p, p_max_size, "%s",
5409 cur->audacious.items[AUDACIOUS_POSITION]);
5411 OBJ(audacious_position_seconds) {
5412 snprintf(p, p_max_size, "%s",
5413 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5415 OBJ(audacious_bitrate) {
5416 snprintf(p, p_max_size, "%s",
5417 cur->audacious.items[AUDACIOUS_BITRATE]);
5419 OBJ(audacious_frequency) {
5420 snprintf(p, p_max_size, "%s",
5421 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5423 OBJ(audacious_channels) {
5424 snprintf(p, p_max_size, "%s",
5425 cur->audacious.items[AUDACIOUS_CHANNELS]);
5427 OBJ(audacious_filename) {
5428 snprintf(p, p_max_size, "%s",
5429 cur->audacious.items[AUDACIOUS_FILENAME]);
5431 OBJ(audacious_playlist_length) {
5432 snprintf(p, p_max_size, "%s",
5433 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5435 OBJ(audacious_playlist_position) {
5436 snprintf(p, p_max_size, "%s",
5437 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5439 OBJ(audacious_bar) {
5443 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5444 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5445 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5451 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5454 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5457 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5460 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5463 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5466 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5470 char *format_time(unsigned long time, const int width)
5473 unsigned long nt; // narrow time, for speed on 32-bit
5474 unsigned cc; // centiseconds
5475 unsigned nn; // multi-purpose whatever
5478 cc = nt % 100; // centiseconds past second
5479 nt /= 100; // total seconds
5480 nn = nt % 60; // seconds past the minute
5481 nt /= 60; // total minutes
5482 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
5486 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
5489 nn = nt % 60; // minutes past the hour
5490 nt /= 60; // total hours
5491 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
5494 nn = nt; // now also hours
5495 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
5498 nn /= 24; // now days
5499 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
5502 nn /= 7; // now weeks
5503 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
5506 // well shoot, this outta' fit...
5507 return strdup("<inf>");
5511 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5514 switch (obj->data.top.type) {
5516 snprintf(p, 16, "%-15s",
5517 cur->cpu[obj->data.top.num]->name);
5520 snprintf(p, 7, "%6.2f",
5521 cur->cpu[obj->data.top.num]->amount);
5524 snprintf(p, 6, "%5i",
5525 cur->cpu[obj->data.top.num]->pid);
5528 snprintf(p, 7, "%6.2f",
5529 cur->cpu[obj->data.top.num]->totalmem);
5533 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5534 snprintf(p, 10, "%9s", time);
5538 ERR("Unhandled top data type: %d\n",
5539 obj->data.top.type);
5542 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5546 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5549 switch (obj->data.top.type) {
5551 snprintf(p, 16, "%-15s",
5552 cur->memu[obj->data.top.num]->name);
5555 snprintf(p, 7, "%6.2f",
5556 cur->memu[obj->data.top.num]->amount);
5559 snprintf(p, 6, "%5i",
5560 cur->memu[obj->data.top.num]->pid);
5563 snprintf(p, 7, "%6.2f",
5564 cur->memu[obj->data.top.num]->totalmem);
5568 cur->memu[obj->data.top.num]->total_cpu_time,
5570 snprintf(p, 10, "%9s", time);
5574 ERR("Unhandled top data type: %d\n",
5575 obj->data.top.type);
5578 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5582 if (current_update_time - obj->data.tail.last_update
5583 < obj->data.tail.interval) {
5584 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5586 obj->data.tail.last_update = current_update_time;
5591 if (obj->data.tail.fd != -1) {
5592 tail_pipe(obj, p, p_max_size);
5596 fp = fopen(obj->data.tail.logfile, "rt");
5599 /* Send one message, but do not consistently spam
5600 * on missing logfiles. */
5601 if (obj->data.tail.readlines != 0) {
5602 ERR("tail logfile failed to open");
5603 strcpy(obj->data.tail.buffer, "Logfile Missing");
5605 obj->data.tail.readlines = 0;
5606 snprintf(p, p_max_size, "Logfile Missing");
5608 obj->data.tail.readlines = 0;
5609 /* -1 instead of 0 to avoid counting a trailing
5611 fseek(fp, -1, SEEK_END);
5612 bsize = ftell(fp) + 1;
5613 for (iter = obj->data.tail.wantedlines; iter > 0;
5615 nl = rev_fcharfind(fp, '\n', iter);
5620 obj->data.tail.readlines = iter;
5621 if (obj->data.tail.readlines
5622 < obj->data.tail.wantedlines) {
5623 fseek(fp, 0, SEEK_SET);
5625 fseek(fp, nl + 1, SEEK_SET);
5628 /* Make sure bsize is at least 1 byte smaller than the
5629 * buffer max size. */
5630 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
5631 fseek(fp, bsize - text_buffer_size * 20 - 1,
5633 bsize = text_buffer_size * 20 - 1;
5635 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5638 /* Clean up trailing newline, make sure the
5639 * buffer is null terminated. */
5640 if (obj->data.tail.buffer[bsize - 1] == '\n') {
5641 obj->data.tail.buffer[bsize - 1] = '\0';
5643 obj->data.tail.buffer[bsize] = '\0';
5645 snprintf(p, p_max_size, "%s",
5646 obj->data.tail.buffer);
5648 strcpy(obj->data.tail.buffer, "Logfile Empty");
5649 snprintf(p, p_max_size, "Logfile Empty");
5652 } /* if cur_upd_time >= */
5653 // parse_conky_vars(obj->data.tail.buffer, p, cur);
5658 if (current_update_time - obj->data.tail.last_update
5659 < obj->data.tail.interval) {
5660 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5662 obj->data.tail.last_update = current_update_time;
5667 fp = fopen(obj->data.tail.logfile, "rt");
5669 /* Send one message, but do not consistently spam
5670 * on missing logfiles. */
5671 if (obj->data.tail.readlines != 0) {
5672 ERR("head logfile failed to open");
5673 strcpy(obj->data.tail.buffer, "Logfile Missing");
5675 obj->data.tail.readlines = 0;
5676 snprintf(p, p_max_size, "Logfile Missing");
5678 obj->data.tail.readlines = 0;
5679 for (iter = obj->data.tail.wantedlines; iter > 0;
5681 nl = fwd_fcharfind(fp, '\n', iter);
5686 obj->data.tail.readlines = iter;
5687 /* Make sure nl is at least 1 byte smaller than the
5688 * buffer max size. */
5689 if (nl > (long) ((text_buffer_size * 20) - 1)) {
5690 nl = text_buffer_size * 20 - 1;
5692 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5695 /* Clean up trailing newline, make sure the buffer
5696 * is null terminated. */
5697 if (obj->data.tail.buffer[nl - 1] == '\n') {
5698 obj->data.tail.buffer[nl - 1] = '\0';
5700 obj->data.tail.buffer[nl] = '\0';
5702 snprintf(p, p_max_size, "%s",
5703 obj->data.tail.buffer);
5705 strcpy(obj->data.tail.buffer, "Logfile Empty");
5706 snprintf(p, p_max_size, "Logfile Empty");
5708 } /* if fp == null */
5709 } /* cur_upd_time >= */
5710 // parse_conky_vars(obj->data.tail.buffer, p, cur);
5713 #ifdef TCP_PORT_MONITOR
5715 /* grab a pointer to this port monitor */
5716 tcp_port_monitor_t *p_monitor =
5717 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
5718 obj->data.tcp_port_monitor.port_range_begin,
5719 obj->data.tcp_port_monitor.port_range_end);
5722 snprintf(p, p_max_size, "monitor not found");
5726 /* now grab the text of interest */
5727 if (peek_tcp_port_monitor(p_monitor,
5728 obj->data.tcp_port_monitor.item,
5729 obj->data.tcp_port_monitor.connection_index, p,
5731 snprintf(p, p_max_size, "monitor peek error");
5739 iconv_converting = 1;
5740 iconv_selected = obj->a;
5743 iconv_converting = 0;
5748 OBJ(entropy_avail) {
5749 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5751 OBJ(entropy_poolsize) {
5752 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5755 double entropy_perc;
5757 entropy_perc = (double) cur->entropy.entropy_avail /
5758 (double) cur->entropy.poolsize;
5759 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5766 unsigned int a = strlen(p);
5769 if (a > 0 && iconv_converting && iconv_selected > 0
5770 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5772 size_t dummy1, dummy2;
5773 char *ptr = buff_in;
5776 dummy1 = dummy2 = a;
5778 strncpy(buff_in, p, P_MAX_SIZE);
5780 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5781 while (dummy1 > 0) {
5782 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5785 ERR("Iconv codeset conversion failed");
5790 /* It is nessecary when we are converting from multibyte to
5791 * singlebyte codepage */
5801 double current_update_time, last_update_time;
5803 static void generate_text()
5805 struct information *cur = &info;
5812 current_update_time = get_time();
5815 /* fix diskio rates to b/s (use update_interval */
5816 diskio_read_value = diskio_read_value / update_interval;
5817 diskio_write_value = diskio_write_value / update_interval;
5818 diskio_value = diskio_value / update_interval;
5820 /* add things to the buffer */
5826 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5828 if (stuff_in_upper_case) {
5838 last_update_time = current_update_time;
5844 static void set_font()
5848 if (window.xftdraw != NULL) {
5849 XftDrawDestroy(window.xftdraw);
5851 window.xftdraw = XftDrawCreate(display, window.drawable,
5852 DefaultVisual(display, screen), DefaultColormap(display, screen));
5856 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5862 static inline int get_string_width(const char *s)
5865 return *s ? calc_text_width(s, strlen(s)) : 0;
5871 static inline int get_string_width_special(char *s)
5886 if (*p == SPECIAL_CHAR) {
5887 /* shift everything over by 1 so that the special char
5888 * doesn't mess up the size calculation */
5889 for (i = 0; i < strlen(p); i++) {
5890 *(p + i) = *(p + i + 1);
5892 if (specials[special_index + index].type == GRAPH
5893 || specials[special_index + index].type == BAR) {
5894 width += specials[special_index + index].width;
5901 if (strlen(final) > 1) {
5902 width += calc_text_width(final, strlen(final));
5912 static void text_size_updater(char *s);
5914 int last_font_height;
5915 static void update_text_area()
5919 /* update text size if it isn't fixed */
5924 text_width = minimum_width;
5927 last_font_height = font_height();
5928 for_each_line(text_buffer, text_size_updater);
5930 if (text_height < minimum_height) {
5931 text_height = minimum_height;
5933 if (text_width > maximum_width && maximum_width > 0) {
5934 text_width = maximum_width;
5938 /* get text position on workarea */
5939 switch (text_alignment) {
5946 x = workarea[2] - text_width - gap_x;
5953 y = workarea[3] - text_height - gap_y;
5957 x = workarea[2] - text_width - gap_x;
5958 y = workarea[3] - text_height - gap_y;
5962 case NONE: // Let the WM manage the window
5973 if (own_window && !fixed_pos) {
5976 text_start_x = border_margin + 1;
5977 text_start_y = border_margin + 1;
5978 window.x = x - border_margin - 1;
5979 window.y = y - border_margin - 1;
5983 /* If window size doesn't match to workarea's size,
5984 * then window probably includes panels (gnome).
5985 * Blah, doesn't work on KDE. */
5986 if (workarea[2] != window.width || workarea[3] != window.height) {
5998 static int cur_x, cur_y; /* current x and y for drawing */
5999 static int draw_mode; /* FG, BG or OUTLINE */
6000 static long current_color;
6003 static void text_size_updater(char *s)
6008 /* get string widths and skip specials */
6011 if (*p == SPECIAL_CHAR) {
6013 w += get_string_width(s);
6016 if (specials[special_index].type == BAR
6017 || specials[special_index].type == GRAPH) {
6018 w += specials[special_index].width;
6019 if (specials[special_index].height > last_font_height) {
6020 last_font_height = specials[special_index].height;
6021 last_font_height += font_ascent();
6023 } else if (specials[special_index].type == OFFSET) {
6024 if (specials[special_index].arg > 0) {
6025 w += specials[special_index].arg;
6027 } else if (specials[special_index].type == VOFFSET) {
6028 last_font_height += specials[special_index].arg;
6029 } else if (specials[special_index].type == GOTO) {
6030 if (specials[special_index].arg > cur_x) {
6031 w = (int) specials[special_index].arg;
6033 } else if (specials[special_index].type == TAB) {
6034 int start = specials[special_index].arg;
6035 int step = specials[special_index].width;
6037 if (!step || step < 0) {
6040 w += step - (cur_x - text_start_x - start) % step;
6041 } else if (specials[special_index].type == FONT) {
6042 selected_font = specials[special_index].font_added;
6043 if (font_height() > last_font_height) {
6044 last_font_height = font_height();
6053 w += get_string_width(s);
6054 if (w > text_width) {
6057 if (text_width > maximum_width && maximum_width) {
6058 text_width = maximum_width;
6061 text_height += last_font_height;
6062 last_font_height = font_height();
6066 static inline void set_foreground_color(long c)
6069 XSetForeground(display, window.gc, c);
6073 static void draw_string(const char *s)
6078 int i, i2, pos, width_of_s;
6082 width_of_s = get_string_width(s);
6083 if (out_to_console) {
6085 fflush(stdout); /* output immediately, don't buffer */
6087 memset(tmpstring1, 0, TEXT_BUFFER_SIZE);
6088 memset(tmpstring2, 0, TEXT_BUFFER_SIZE);
6089 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE - 1);
6094 snprintf(space, 2, " ");
6096 max = ((text_width - width_of_s) / get_string_width(space));
6098 /* This code looks for tabs in the text and coverts them to spaces.
6099 * The trick is getting the correct number of spaces, and not going
6100 * over the window's size without forcing the window larger. */
6101 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
6102 if (tmpstring1[i] == '\t') { // 9 is ascii tab
6104 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6105 /* if (pos + i2 > TEXT_BUFFER_SIZE - 1) {
6106 fprintf(stderr, "buffer overrun detected\n");
6108 /* guard against overrun */
6109 tmpstring2[MIN(pos + i2, TEXT_BUFFER_SIZE - 1)] = ' ';
6114 if (tmpstring1[i] != 9) {
6115 /* if (pos > TEXT_BUFFER_SIZE - 1) {
6116 fprintf(stderr, "buffer overrun detected\n");
6118 /* guard against overrun */
6119 tmpstring2[MIN(pos, TEXT_BUFFER_SIZE - 1)] = tmpstring1[i];
6125 if (text_width == maximum_width) {
6126 /* this means the text is probably pushing the limit,
6127 * so we'll chop it */
6128 while (cur_x + get_string_width(tmpstring2) - text_start_x
6129 > maximum_width && strlen(tmpstring2) > 0) {
6130 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6141 c.pixel = current_color;
6142 XQueryColor(display, DefaultColormap(display, screen), &c);
6145 c2.color.red = c.red;
6146 c2.color.green = c.green;
6147 c2.color.blue = c.blue;
6148 c2.color.alpha = fonts[selected_font].font_alpha;
6150 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6151 cur_x, cur_y, (XftChar8 *) s, strlen(s));
6153 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6154 cur_x, cur_y, (XftChar8 *) s, strlen(s));
6159 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6162 cur_x += width_of_s;
6164 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
6167 long redmask, greenmask, bluemask;
6169 void set_up_gradient()
6172 colour_depth = DisplayPlanes(display, screen);
6176 if (colour_depth != 24 && colour_depth != 16) {
6177 ERR("using non-standard colour depth, gradients may look like a "
6185 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6187 greenmask |= 1 << i;
6190 if (colour_depth % 3 == 1) {
6191 greenmask |= 1 << (colour_depth / 3);
6193 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6194 greenmask = greenmask << (colour_depth / 3);
6197 /* this function returns the next colour between two colours for a gradient */
6198 inline unsigned long do_gradient(unsigned long first_colour,
6199 unsigned long last_colour)
6202 int red1, green1, blue1; // first colour
6203 int red2, green2, blue2; // second colour
6204 int red3 = 0, green3 = 0, blue3 = 0; // difference
6205 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6206 short greenshift = (colour_depth / 3);
6208 red1 = (first_colour & redmask) >> redshift;
6209 green1 = (first_colour & greenmask) >> greenshift;
6210 blue1 = first_colour & bluemask;
6211 red2 = (last_colour & redmask) >> redshift;
6212 green2 = (last_colour & greenmask) >> greenshift;
6213 blue2 = last_colour & bluemask;
6220 if (green1 > green2) {
6223 if (green1 < green2) {
6226 if (blue1 > blue2) {
6229 if (blue1 < blue2) {
6244 if (red1 > bluemask) {
6247 if (green1 > bluemask) {
6250 if (blue1 > bluemask) {
6253 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6257 /* this function returns the max diff for a gradient */
6258 inline unsigned long gradient_max(unsigned long first_colour,
6259 unsigned long last_colour)
6261 if (colour_depth == 0) {
6264 int red1, green1, blue1; // first colour
6265 int red2, green2, blue2; // second colour
6266 long redshift = (2 * colour_depth / 3 + colour_depth % 3);
6267 long greenshift = (colour_depth / 3);
6268 int red3 = 0, green3 = 0, blue3 = 0; // difference
6270 red1 = (first_colour & redmask) >> redshift;
6271 green1 = (first_colour & greenmask) >> greenshift;
6272 blue1 = first_colour & bluemask;
6273 red2 = (last_colour & redmask) >> redshift;
6274 green2 = (last_colour & greenmask) >> greenshift;
6275 blue2 = last_colour & bluemask;
6276 red3 = abs(red1 - red2);
6277 green3 = abs(green1 - green2);
6278 blue3 = abs(blue1 - blue2);
6290 static void draw_line(char *s)
6295 cur_x = text_start_x;
6296 cur_y += font_ascent();
6298 short font_h = font_height();
6300 /* find specials and draw stuff */
6303 if (*p == SPECIAL_CHAR) {
6306 /* draw string before special */
6313 switch (specials[special_index].type) {
6314 case HORIZONTAL_LINE:
6316 int h = specials[special_index].height;
6317 int mid = font_ascent() / 2;
6319 w = text_start_x + text_width - cur_x;
6321 XSetLineAttributes(display, window.gc, h, LineSolid,
6322 CapButt, JoinMiter);
6323 XDrawLine(display, window.drawable, window.gc, cur_x,
6324 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6330 int h = specials[special_index].height;
6331 int s = specials[special_index].arg;
6332 int mid = font_ascent() / 2;
6333 char ss[2] = { s, s };
6335 w = text_start_x + text_width - cur_x - 1;
6336 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6337 CapButt, JoinMiter);
6338 XSetDashes(display, window.gc, 0, ss, 2);
6339 XDrawLine(display, window.drawable, window.gc, cur_x,
6340 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6346 if (cur_x - text_start_x > maximum_width
6347 && maximum_width > 0) {
6350 int h = specials[special_index].height;
6351 int bar_usage = specials[special_index].arg;
6352 int by = cur_y - (font_ascent() / 2) - 1;
6354 if (h < font_height()) {
6357 w = specials[special_index].width;
6359 w = text_start_x + text_width - cur_x - 1;
6365 XSetLineAttributes(display, window.gc, 1, LineSolid,
6366 CapButt, JoinMiter);
6368 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6370 XFillRectangle(display, window.drawable, window.gc, cur_x,
6371 by, w * bar_usage / 255, h);
6372 if (specials[special_index].height > cur_y_add
6373 && specials[special_index].height > font_h) {
6374 cur_y_add = specials[special_index].height;
6381 if (cur_x - text_start_x > maximum_width
6382 && maximum_width > 0) {
6385 int h = specials[special_index].height;
6386 unsigned long last_colour = current_color;
6387 int by = cur_y - (font_ascent() / 2) - 1;
6389 if (h < font_height()) {
6392 w = specials[special_index].width;
6394 w = text_start_x + text_width - cur_x - 1;
6399 if (draw_graph_borders) {
6400 XSetLineAttributes(display, window.gc, 1, LineSolid,
6401 CapButt, JoinMiter);
6402 XDrawRectangle(display, window.drawable, window.gc,
6405 XSetLineAttributes(display, window.gc, 1, LineSolid,
6406 CapButt, JoinMiter);
6409 int gradient_size = 0;
6410 float gradient_factor = 0;
6411 float gradient_update = 0;
6412 unsigned long tmpcolour = current_color;
6414 if (specials[special_index].last_colour != 0
6415 || specials[special_index].first_colour != 0) {
6416 tmpcolour = specials[special_index].last_colour;
6418 gradient_max(specials[special_index].last_colour,
6419 specials[special_index].first_colour);
6420 gradient_factor = (float) gradient_size / (w - 2);
6422 for (i = w - 2; i > -1; i--) {
6423 if (specials[special_index].last_colour != 0
6424 || specials[special_index].first_colour != 0) {
6425 XSetForeground(display, window.gc, tmpcolour);
6426 gradient_update += gradient_factor;
6427 while (gradient_update > 0) {
6428 tmpcolour = do_gradient(tmpcolour,
6429 specials[special_index].first_colour);
6433 if ((w - i) / ((float) (w - 2) /
6434 (specials[special_index].graph_width)) > j
6435 && j < MAX_GRAPH_DEPTH - 3) {
6438 /* this is mugfugly, but it works */
6439 XDrawLine(display, window.drawable, window.gc,
6440 cur_x + i + 1, by + h, cur_x + i + 1,
6441 by + h - specials[special_index].graph[j] *
6442 (h - 1) / specials[special_index].graph_scale);
6444 if (specials[special_index].height > cur_y_add
6445 && specials[special_index].height > font_h) {
6446 cur_y_add = specials[special_index].height;
6448 /* if (draw_mode == BG) {
6449 set_foreground_color(default_bg_color);
6450 } else if (draw_mode == OUTLINE) {
6451 set_foreground_color(default_out_color);
6453 set_foreground_color(default_fg_color);
6455 set_foreground_color(last_colour);
6461 int old = font_ascent();
6463 cur_y -= font_ascent();
6464 selected_font = specials[special_index].font_added;
6465 if (cur_y + font_ascent() < cur_y + old) {
6468 cur_y += font_ascent();
6474 if (draw_mode == FG) {
6475 set_foreground_color(specials[special_index].arg);
6480 if (draw_mode == BG) {
6481 set_foreground_color(specials[special_index].arg);
6486 if (draw_mode == OUTLINE) {
6487 set_foreground_color(specials[special_index].arg);
6492 w += specials[special_index].arg;
6496 cur_y += specials[special_index].arg;
6500 if (specials[special_index].arg >= 0) {
6501 cur_x = (int) specials[special_index].arg;
6507 int start = specials[special_index].arg;
6508 int step = specials[special_index].width;
6510 if (!step || step < 0) {
6513 w = step - (cur_x - text_start_x - start) % step;
6519 /* TODO: add back in "+ border_margin" to the end of
6521 int pos_x = text_start_x + text_width -
6522 get_string_width_special(s);
6524 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6525 "get_string_width(p) %i gap_x %i "
6526 "specials[special_index].arg %i border_margin %i "
6527 "border_width %i\n", pos_x, text_start_x, text_width,
6528 cur_x, get_string_width_special(s), gap_x,
6529 specials[special_index].arg, border_margin,
6531 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6532 cur_x = pos_x - specials[special_index].arg;
6539 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6540 2 - (cur_x - text_start_x);
6541 /* int pos_x = text_start_x + text_width / 2 -
6542 get_string_width_special(s) / 2; */
6544 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6545 "get_string_width(p) %i gap_x %i "
6546 "specials[special_index].arg %i\n", pos_x, text_start_x,
6547 text_width, cur_x, get_string_width(s), gap_x,
6548 specials[special_index].arg); */
6549 if (pos_x > specials[special_index].arg) {
6550 w = pos_x - specials[special_index].arg;
6567 if (cur_y_add > 0) {
6569 cur_y -= font_descent();
6574 cur_y += font_descent();
6578 static void draw_text()
6581 cur_y = text_start_y;
6584 if (draw_borders && border_width > 0) {
6585 unsigned int b = (border_width + 1) / 2;
6587 if (stippled_borders) {
6588 char ss[2] = { stippled_borders, stippled_borders };
6589 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6590 CapButt, JoinMiter);
6591 XSetDashes(display, window.gc, 0, ss, 2);
6593 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6594 CapButt, JoinMiter);
6597 XDrawRectangle(display, window.drawable, window.gc,
6598 text_start_x - border_margin + b, text_start_y - border_margin + b,
6599 text_width + border_margin * 2 - 1 - b * 2,
6600 text_height + border_margin * 2 - 1 - b * 2);
6606 for_each_line(text_buffer, draw_line);
6609 static void draw_stuff()
6613 if (draw_shades && !draw_outline) {
6616 set_foreground_color(default_bg_color);
6627 for (i = -1; i < 2; i++) {
6628 for (j = -1; j < 2; j++) {
6629 if (i == 0 && j == 0) {
6634 set_foreground_color(default_out_color);
6635 draw_mode = OUTLINE;
6643 set_foreground_color(default_fg_color);
6652 swap.swap_window = window.window;
6653 swap.swap_action = XdbeBackground;
6654 XdbeSwapBuffers(display, &swap, 1);
6661 static void clear_text(int exposures)
6665 /* The swap action is XdbeBackground, which clears */
6670 /* there is some extra space for borders and outlines */
6671 XClearArea(display, window.window, text_start_x - border_margin - 1,
6672 text_start_y - border_margin - 1,
6673 text_width + border_margin * 2 + 2,
6674 text_height + border_margin * 2 + 2, exposures ? True : 0);
6679 static int need_to_update;
6681 /* update_text() generates new text and clears old text area */
6682 static void update_text()
6691 static void main_loop()
6693 #ifdef SIGNAL_BLOCKING
6694 sigset_t newmask, oldmask;
6696 sigemptyset(&newmask);
6697 sigaddset(&newmask, SIGINT);
6698 sigaddset(&newmask, SIGTERM);
6699 sigaddset(&newmask, SIGUSR1);
6703 Region region = XCreateRegion();
6706 int event_base, error_base;
6708 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
6709 ERR("Xdamage extension unavailable");
6711 Damage damage = XDamageCreate(display, window.window,
6712 XDamageReportNonEmpty);
6713 XserverRegion region2 = XFixesCreateRegionFromWindow(display,
6715 XserverRegion part = XFixesCreateRegionFromWindow(display,
6717 #endif /* HAVE_XDAMAGE */
6721 while (total_run_times == 0 || info.looped < total_run_times) {
6724 #ifdef SIGNAL_BLOCKING
6725 /* block signals. we will inspect for pending signals later */
6726 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6727 CRIT_ERR("unable to sigprocmask()");
6734 /* wait for X event or timeout */
6736 if (!XPending(display)) {
6740 double t = update_interval - (get_time() - last_update_time);
6746 tv.tv_sec = (long) t;
6747 tv.tv_usec = (long) (t * 1000000) % 1000000;
6749 FD_SET(ConnectionNumber(display), &fdsr);
6751 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6753 if (errno != EINTR) {
6754 ERR("can't select(): %s", strerror(errno));
6760 /* FIXME just sleep for the interval time if no X11 */
6761 usleep(update_interval * 1000000);
6769 if (need_to_update) {
6771 int wx = window.x, wy = window.y;
6779 /* resize window if it isn't right size */
6781 && (text_width + border_margin * 2 + 1 != window.width
6782 || text_height + border_margin * 2 + 1 != window.height)) {
6783 window.width = text_width + border_margin * 2 + 1;
6784 window.height = text_height + border_margin * 2 + 1;
6785 XResizeWindow(display, window.window, window.width,
6788 set_transparent_background(window.window);
6792 /* move window if it isn't in right position */
6793 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6794 XMoveWindow(display, window.window, window.x, window.y);
6805 r.x = text_start_x - border_margin;
6806 r.y = text_start_y - border_margin;
6807 r.width = text_width + border_margin * 2;
6808 r.height = text_height + border_margin * 2;
6809 XUnionRectWithRegion(&r, region, region);
6814 /* handle X events */
6815 while (XPending(display)) {
6818 XNextEvent(display, &ev);
6826 r.width = ev.xexpose.width;
6827 r.height = ev.xexpose.height;
6828 XUnionRectWithRegion(&r, region, region);
6833 case ReparentNotify:
6834 /* set background to ParentRelative for all parents */
6836 set_transparent_background(window.window);
6840 case ConfigureNotify:
6842 /* if window size isn't what expected, set fixed size */
6843 if (ev.xconfigure.width != window.width
6844 || ev.xconfigure.height != window.height) {
6845 if (window.width != 0 && window.height != 0) {
6849 /* clear old stuff before screwing up
6854 XWindowAttributes attrs;
6856 if (XGetWindowAttributes(display,
6857 window.window, &attrs)) {
6858 window.width = attrs.width;
6859 window.height = attrs.height;
6863 text_width = window.width - border_margin * 2 - 1;
6864 text_height = window.height - border_margin * 2 - 1;
6865 if (text_width > maximum_width
6866 && maximum_width > 0) {
6867 text_width = maximum_width;
6871 /* if position isn't what expected, set fixed pos
6872 * total_updates avoids setting fixed_pos when window
6873 * is set to weird locations when started */
6874 /* // this is broken
6875 if (total_updates >= 2 && !fixed_pos
6876 && (window.x != ev.xconfigure.x
6877 || window.y != ev.xconfigure.y)
6878 && (ev.xconfigure.x != 0
6879 || ev.xconfigure.y != 0)) {
6888 /* if an ordinary window with decorations */
6889 if ((window.type == TYPE_NORMAL)
6890 && (!TEST_HINT(window.hints,
6891 HINT_UNDECORATED))) {
6892 /* allow conky to hold input focus. */
6895 /* forward the click to the desktop window */
6896 XUngrabPointer(display, ev.xbutton.time);
6897 ev.xbutton.window = window.desktop;
6898 XSendEvent(display, ev.xbutton.window, False,
6899 ButtonPressMask, &ev);
6900 XSetInputFocus(display, ev.xbutton.window,
6901 RevertToParent, ev.xbutton.time);
6908 /* if an ordinary window with decorations */
6909 if ((window.type == TYPE_NORMAL)
6910 && (!TEST_HINT(window.hints,
6911 HINT_UNDECORATED))) {
6912 /* allow conky to hold input focus. */
6915 /* forward the release to the desktop window */
6916 ev.xbutton.window = window.desktop;
6917 XSendEvent(display, ev.xbutton.window, False,
6918 ButtonReleaseMask, &ev);
6927 if (ev.type == event_base + XDamageNotify) {
6928 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6930 XFixesSetRegion(display, part, &dev->area, 1);
6931 XFixesUnionRegion(display, region2, region2, part);
6933 #endif /* HAVE_XDAMAGE */
6939 XDamageSubtract(display, damage, region2, None);
6940 XFixesSetRegion(display, region2, 0, 0);
6941 #endif /* HAVE_XDAMAGE */
6943 /* XDBE doesn't seem to provide a way to clear the back buffer without
6944 * interfering with the front buffer, other than passing XdbeBackground
6945 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6946 * redraw the text even if it wasn't part of the exposed area. OTOH,
6947 * if we're not going to call draw_stuff at all, then no swap happens
6948 * and we can safely do nothing. */
6950 if (!XEmptyRegion(region)) {
6955 r.x = text_start_x - border_margin;
6956 r.y = text_start_y - border_margin;
6957 r.width = text_width + border_margin * 2;
6958 r.height = text_height + border_margin * 2;
6959 XUnionRectWithRegion(&r, region, region);
6962 XSetRegion(display, window.gc, region);
6965 XftDrawSetClip(window.xftdraw, region);
6971 XDestroyRegion(region);
6972 region = XCreateRegion();
6976 #ifdef SIGNAL_BLOCKING
6977 /* unblock signals of interest and let handler fly */
6978 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6979 CRIT_ERR("unable to sigprocmask()");
6983 switch (g_signal_pending) {
6985 ERR("received SIGUSR1. reloading the config file.");
6990 ERR("received SIGINT or SIGTERM to terminate. bye!");
6993 XDestroyRegion(region);
6996 return; /* return from main_loop */
6999 /* Reaching here means someone set a signal
7000 * (SIGXXXX, signal_handler), but didn't write any code
7002 * If you don't want to handle a signal, don't set a handler on
7003 * it in the first place. */
7004 if (g_signal_pending) {
7005 ERR("ignoring signal (%d)", g_signal_pending);
7009 g_signal_pending = 0;
7012 #if defined(X11) && defined(HAVE_XDAMAGE)
7013 XDamageDestroy(display, damage);
7014 XFixesDestroyRegion(display, region2);
7015 XFixesDestroyRegion(display, part);
7016 XDestroyRegion(region);
7018 #endif /* X11 && HAVE_XDAMAGE */
7021 static void load_config_file(const char *);
7023 /* reload the config file */
7024 void reload_config(void)
7026 timed_thread_destroy_registered_threads();
7028 if (info.cpu_usage) {
7029 free(info.cpu_usage);
7030 info.cpu_usage = NULL;
7038 if (info.mpd.title) {
7039 free(info.mpd.title);
7040 info.mpd.title = NULL;
7042 if (info.mpd.artist) {
7043 free(info.mpd.artist);
7044 info.mpd.artist = NULL;
7046 if (info.mpd.album) {
7047 free(info.mpd.album);
7048 info.mpd.album = NULL;
7050 if (info.mpd.random) {
7051 free(info.mpd.random);
7052 info.mpd.random = NULL;
7054 if (info.mpd.repeat) {
7055 free(info.mpd.repeat);
7056 info.mpd.repeat = NULL;
7058 if (info.mpd.track) {
7059 free(info.mpd.track);
7060 info.mpd.track = NULL;
7062 if (info.mpd.name) {
7063 free(info.mpd.name);
7064 info.mpd.name = NULL;
7066 if (info.mpd.file) {
7067 free(info.mpd.file);
7068 info.mpd.file = NULL;
7070 if (info.mpd.status) {
7071 free(info.mpd.status);
7072 info.mpd.status = NULL;
7080 #ifdef TCP_PORT_MONITOR
7081 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7084 if (current_config) {
7086 load_config_file(current_config);
7088 /* re-init specials array */
7089 if ((specials = realloc((void *) specials,
7090 sizeof(struct special_t) * max_specials)) == 0) {
7091 ERR("failed to realloc specials array");
7098 // clear the window first
7099 XClearWindow(display, RootWindow(display, screen));
7102 #ifdef TCP_PORT_MONITOR
7103 info.p_tcp_port_monitor_collection = NULL;
7105 extract_variable_text(text);
7114 timed_thread_destroy_registered_threads();
7116 if (info.cpu_usage) {
7117 free(info.cpu_usage);
7118 info.cpu_usage = NULL;
7123 XdbeDeallocateBackBufferName(display, window.back_buffer);
7128 XDestroyWindow(display, window.window);
7129 XClearWindow(display, RootWindow(display, screen));
7134 XClearWindow(display, RootWindow(display, screen));
7139 XFreeGC(display, window.gc);
7143 free_text_objects(text_object_count, text_objects);
7144 text_object_count = 0;
7145 text_objects = NULL;
7151 free(current_config);
7153 #ifdef TCP_PORT_MONITOR
7154 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7155 info.p_tcp_port_monitor_collection = NULL;
7164 for (i = 0; i < special_count; i++) {
7165 if (specials[i].type == GRAPH) {
7166 free(specials[i].graph);
7173 clear_diskio_stats();
7176 static int string_to_bool(const char *s)
7180 } else if (strcasecmp(s, "yes") == 0) {
7182 } else if (strcasecmp(s, "true") == 0) {
7184 } else if (strcasecmp(s, "1") == 0) {
7191 static enum alignment string_to_alignment(const char *s)
7193 if (strcasecmp(s, "top_left") == 0) {
7195 } else if (strcasecmp(s, "top_right") == 0) {
7197 } else if (strcasecmp(s, "bottom_left") == 0) {
7199 } else if (strcasecmp(s, "bottom_right") == 0) {
7200 return BOTTOM_RIGHT;
7201 } else if (strcasecmp(s, "tl") == 0) {
7203 } else if (strcasecmp(s, "tr") == 0) {
7205 } else if (strcasecmp(s, "bl") == 0) {
7207 } else if (strcasecmp(s, "br") == 0) {
7208 return BOTTOM_RIGHT;
7209 } else if (strcasecmp(s, "none") == 0) {
7216 static void set_default_configurations(void)
7218 fork_to_background = 0;
7219 total_run_times = 0;
7220 info.cpu_avg_samples = 2;
7221 info.net_avg_samples = 2;
7228 strcpy(info.mpd.host, "localhost");
7229 info.mpd.port = 6600;
7230 info.mpd.status = NULL;
7231 info.mpd.artist = NULL;
7232 info.mpd.album = NULL;
7233 info.mpd.title = NULL;
7234 info.mpd.random = NULL;
7235 info.mpd.track = NULL;
7236 info.mpd.name = NULL;
7237 info.mpd.file = NULL;
7240 info.xmms2.artist = NULL;
7241 info.xmms2.album = NULL;
7242 info.xmms2.title = NULL;
7243 info.xmms2.genre = NULL;
7244 info.xmms2.comment = NULL;
7245 info.xmms2.decoder = NULL;
7246 info.xmms2.transport = NULL;
7247 info.xmms2.url = NULL;
7248 info.xmms2.status = NULL;
7250 use_spacer = NO_SPACER;
7257 default_fg_color = WhitePixel(display, screen);
7258 default_bg_color = BlackPixel(display, screen);
7259 default_out_color = BlackPixel(display, screen);
7260 color0 = default_fg_color;
7261 color1 = default_fg_color;
7262 color2 = default_fg_color;
7263 color3 = default_fg_color;
7264 color4 = default_fg_color;
7265 color5 = default_fg_color;
7266 color6 = default_fg_color;
7267 color7 = default_fg_color;
7268 color8 = default_fg_color;
7269 color9 = default_fg_color;
7272 draw_graph_borders = 1;
7274 set_first_font("6x10");
7282 window.type = TYPE_NORMAL;
7284 strcpy(window.class_name, "Conky");
7286 sprintf(window.title, "Conky (%s)", info.uname_s.nodename);
7288 stippled_borders = 0;
7291 text_alignment = BOTTOM_LEFT;
7294 free(current_mail_spool);
7298 variable_substitute(MAIL_FILE, buf, 256);
7299 if (buf[0] != '\0') {
7300 current_mail_spool = strdup(buf);
7305 update_interval = 3.0;
7306 info.music_player_interval = 1.0;
7307 stuff_in_upper_case = 0;
7309 #ifdef TCP_PORT_MONITOR
7310 tcp_port_monitor_args.max_port_monitor_connections =
7311 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7315 static void load_config_file(const char *f)
7317 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7321 set_default_configurations();
7328 char buf[256], *p, *p2, *name, *value;
7331 if (fgets(buf, 256, fp) == NULL) {
7337 /* break at comment */
7338 p2 = strchr(p, '#');
7344 while (*p && isspace((int) *p)) {
7348 continue; /* empty line */
7355 while (*p2 && !isspace((int) *p2)) {
7359 *p2 = '\0'; /* break at name's end */
7366 while (*p && isspace((int) *p)) {
7372 p2 = value + strlen(value);
7373 while (isspace((int) *(p2 - 1))) {
7380 #define CONF2(a) if (strcasecmp(name, a) == 0)
7381 #define CONF(a) else CONF2(a)
7382 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7383 || strcasecmp(name, b) == 0)
7386 CONF2("alignment") {
7388 int a = string_to_alignment(value);
7399 CONF("background") {
7400 fork_to_background = string_to_bool(value);
7403 CONF2("background") {
7404 fork_to_background = string_to_bool(value);
7408 CONF("border_margin") {
7410 border_margin = strtol(value, 0, 0);
7415 CONF("border_width") {
7417 border_width = strtol(value, 0, 0);
7424 color0 = get_x11_color(value);
7431 color1 = get_x11_color(value);
7438 color2 = get_x11_color(value);
7445 color3 = get_x11_color(value);
7452 color4 = get_x11_color(value);
7459 color5 = get_x11_color(value);
7466 color6 = get_x11_color(value);
7473 color7 = get_x11_color(value);
7480 color8 = get_x11_color(value);
7487 color9 = get_x11_color(value);
7492 CONF("default_color") {
7494 default_fg_color = get_x11_color(value);
7499 CONF3("default_shade_color", "default_shadecolor") {
7501 default_bg_color = get_x11_color(value);
7506 CONF3("default_outline_color", "default_outlinecolor") {
7508 default_out_color = get_x11_color(value);
7516 info.mail = parse_mail_args(IMAP, value);
7523 info.mail = parse_mail_args(POP3, value);
7531 strncpy(info.mpd.host, value, 127);
7538 info.mpd.port = strtol(value, 0, 0);
7539 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
7544 CONF("mpd_password") {
7546 strncpy(info.mpd.password, value, 127);
7552 CONF("music_player_interval") {
7554 info.music_player_interval = strtod(value, 0);
7560 CONF("sensor_device") {
7562 sensor_device = strtol(value, 0, 0);
7568 CONF("cpu_avg_samples") {
7570 cpu_avg_samples = strtol(value, 0, 0);
7571 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7574 info.cpu_avg_samples = cpu_avg_samples;
7580 CONF("net_avg_samples") {
7582 net_avg_samples = strtol(value, 0, 0);
7583 if (net_avg_samples < 1 || net_avg_samples > 14) {
7586 info.net_avg_samples = net_avg_samples;
7594 CONF("double_buffer") {
7595 use_xdbe = string_to_bool(value);
7599 CONF("override_utf8_locale") {
7600 utf8_mode = string_to_bool(value);
7602 CONF("draw_borders") {
7603 draw_borders = string_to_bool(value);
7605 CONF("draw_graph_borders") {
7606 draw_graph_borders = string_to_bool(value);
7608 CONF("draw_shades") {
7609 draw_shades = string_to_bool(value);
7611 CONF("draw_outline") {
7612 draw_outline = string_to_bool(value);
7615 CONF("out_to_console") {
7616 out_to_console = string_to_bool(value);
7618 CONF("use_spacer") {
7620 if (strcasecmp(value, "left") == 0) {
7621 use_spacer = LEFT_SPACER;
7622 } else if (strcasecmp(value, "right") == 0) {
7623 use_spacer = RIGHT_SPACER;
7624 } else if (strcasecmp(value, "none") == 0) {
7625 use_spacer = NO_SPACER;
7627 use_spacer = string_to_bool(value);
7628 ERR("use_spacer should have an argument of left, right, or"
7629 " none. '%s' seems to be some form of '%s', so"
7630 " defaulting to %s.", value,
7631 use_spacer ? "true" : "false",
7632 use_spacer ? "right" : "none");
7634 use_spacer = RIGHT_SPACER;
7636 use_spacer = NO_SPACER;
7640 ERR("use_spacer should have an argument. Defaulting to right.");
7641 use_spacer = RIGHT_SPACER;
7647 use_xft = string_to_bool(value);
7651 set_first_font(value);
7657 if (value && font_count >= 0) {
7658 fonts[0].font_alpha = atof(value) * 65535.0;
7667 if (string_to_bool(value)) {
7668 ERR("Xft not enabled");
7672 /* xftfont silently ignored when no Xft */
7675 /* xftalpha is silently ignored when no Xft */
7680 set_first_font(value);
7690 gap_x = atoi(value);
7697 gap_y = atoi(value);
7703 CONF("mail_spool") {
7707 variable_substitute(value, buf, 256);
7709 if (buf[0] != '\0') {
7710 if (current_mail_spool) {
7711 free(current_mail_spool);
7713 current_mail_spool = strdup(buf);
7720 CONF("minimum_size") {
7722 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7724 if (sscanf(value, "%d", &minimum_width) != 1) {
7732 CONF("maximum_width") {
7734 if (sscanf(value, "%d", &maximum_width) != 1) {
7742 CONF("no_buffers") {
7743 no_buffers = string_to_bool(value);
7745 CONF("top_cpu_separate") {
7746 cpu_separate = string_to_bool(value);
7748 CONF("short_units") {
7749 short_units = string_to_bool(value);
7751 CONF("pad_percents") {
7752 pad_percents = atoi(value);
7756 CONF("own_window") {
7758 own_window = string_to_bool(value);
7763 CONF("own_window_class") {
7765 memset(window.class_name, 0, sizeof(window.class_name));
7766 strncpy(window.class_name, value,
7767 sizeof(window.class_name) - 1);
7772 CONF("own_window_title") {
7774 memset(window.title, 0, sizeof(window.title));
7775 strncpy(window.title, value, sizeof(window.title) - 1);
7780 CONF("own_window_transparent") {
7782 set_transparent = string_to_bool(value);
7787 CONF("own_window_colour") {
7789 background_colour = get_x11_color(value);
7791 ERR("Invalid colour for own_window_colour (try omitting the "
7792 "'#' for hex colours");
7795 CONF("own_window_hints") {
7797 char *p_hint, *p_save;
7798 char delim[] = ", ";
7800 /* tokenize the value into individual hints */
7801 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
7803 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
7804 if (strncmp(p_hint, "undecorate", 10) == 0) {
7805 SET_HINT(window.hints, HINT_UNDECORATED);
7806 } else if (strncmp(p_hint, "below", 5) == 0) {
7807 SET_HINT(window.hints, HINT_BELOW);
7808 } else if (strncmp(p_hint, "above", 5) == 0) {
7809 SET_HINT(window.hints, HINT_ABOVE);
7810 } else if (strncmp(p_hint, "sticky", 6) == 0) {
7811 SET_HINT(window.hints, HINT_STICKY);
7812 } else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
7813 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
7814 } else if (strncmp(p_hint, "skip_pager", 10) == 0) {
7815 SET_HINT(window.hints, HINT_SKIP_PAGER);
7820 p_hint = strtok_r(NULL, delim, &p_save);
7821 } while (p_hint != NULL);
7827 CONF("own_window_type") {
7829 if (strncmp(value, "normal", 6) == 0) {
7830 window.type = TYPE_NORMAL;
7831 } else if (strncmp(value, "desktop", 7) == 0) {
7832 window.type = TYPE_DESKTOP;
7833 } else if (strncmp(value, "override", 8) == 0) {
7834 window.type = TYPE_OVERRIDE;
7843 CONF("stippled_borders") {
7845 stippled_borders = strtol(value, 0, 0);
7847 stippled_borders = 4;
7852 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
7856 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
7859 CONF("update_interval") {
7861 update_interval = strtod(value, 0);
7865 if (info.music_player_interval == 0) {
7866 // default to update_interval
7867 info.music_player_interval = update_interval;
7870 CONF("total_run_times") {
7872 total_run_times = strtod(value, 0);
7878 stuff_in_upper_case = string_to_bool(value);
7880 CONF("max_specials") {
7882 max_specials = atoi(value);
7887 CONF("max_user_text") {
7889 max_user_text = atoi(value);
7894 CONF("text_buffer_size") {
7896 text_buffer_size = atoi(value);
7906 text = (char *) malloc(1);
7910 unsigned int l = strlen(text);
7912 if (fgets(buf, 256, fp) == NULL) {
7915 text = (char *) realloc(text, l + strlen(buf) + 1);
7918 if (strlen(text) > max_user_text) {
7923 text_lines = line + 1;
7926 #ifdef TCP_PORT_MONITOR
7927 CONF("max_port_monitor_connections") {
7928 if (!value || (sscanf(value, "%d",
7929 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7930 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
7931 /* an error. use default, warn and continue. */
7932 tcp_port_monitor_args.max_port_monitor_connections =
7933 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7935 } else if (tcp_port_monitor_args.max_port_monitor_connections
7937 /* no error, just use default */
7938 tcp_port_monitor_args.max_port_monitor_connections =
7939 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7941 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
7946 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7957 if (info.music_player_interval == 0) {
7958 // default to update_interval
7959 info.music_player_interval = update_interval;
7963 /* : means that character before that takes an argument */
7964 static const char *getopt_string = "vVdt:u:i:hc:"
7976 static const struct option longopts[] = {
7977 { "help", 0, NULL, 'h' },
7978 { "version", 0, NULL, 'V' },
7979 { "config", 1, NULL, 'c' },
7980 { "daemonize", 0, NULL, 'd' },
7982 { "alignment", 1, NULL, 'a' },
7983 { "font", 1, NULL, 'f' },
7985 { "own-window", 0, NULL, 'o' },
7988 { "double-buffer", 0, NULL, 'b' },
7990 { "window-id", 1, NULL, 'w' },
7992 { "text", 1, NULL, 't' },
7993 { "interval", 0, NULL, 'u' },
7997 int main(int argc, char **argv)
7999 struct sigaction act, oact;
8001 g_signal_pending = 0;
8002 memset(&info, 0, sizeof(info));
8004 #ifdef TCP_PORT_MONITOR
8005 tcp_port_monitor_args.max_port_monitor_connections =
8006 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8009 /* handle command line parameters that don't change configs */
8014 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8015 || ((s = getenv("LANG")) && *s)) {
8016 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8018 ERR("malloc failed");
8020 for (x = 0; x < strlen(s); x++) {
8021 temp[x] = tolower(s[x]);
8024 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8030 if (!setlocale(LC_CTYPE, "")) {
8031 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8035 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8046 if (current_config) {
8047 free(current_config);
8049 current_config = strdup(optarg);
8053 printf("Usage: %s [OPTION]...\n"
8054 "Conky is a system monitor that renders text on desktop or to own transparent\n"
8055 "window. Command line options will override configurations defined in config\n"
8057 " -V, --version version\n"
8058 " -c, --config=FILE config file to load\n"
8059 " -d, --daemonize daemonize, fork to background\n"
8060 " -h, --help help\n"
8062 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
8063 " -f, --font=FONT font to use\n"
8065 " -o, --own-window create own window to draw\n"
8068 " -b, --double-buffer double buffer (prevents flickering)\n"
8070 " -w, --window-id=WIN_ID window id to draw\n"
8071 " -x X x position\n"
8072 " -y Y y position\n"
8074 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8075 " -u, --interval=SECS update interval\n"
8076 " -i NUM number of times to update Conky\n",
8082 window.window = strtol(optarg, 0, 0);
8091 /* initalize X BEFORE we load config.
8092 * (we need to so that 'screen' is set) */
8096 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8098 if (!current_config) {
8099 /* load default config file */
8103 /* Try to use personal config file first */
8104 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8105 if (buf[0] && (fp = fopen(buf, "r"))) {
8106 current_config = strdup(buf);
8110 /* Try to use system config file if personal config not readable */
8111 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8112 current_config = strdup(SYSTEM_CONFIG_FILE);
8116 /* No readable config found */
8117 if (!current_config) {
8118 CRIT_ERR("no readable personal or system-wide config file found");
8122 load_config_file(current_config);
8124 /* init specials array */
8125 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8126 ERR("failed to create specials array");
8130 if (current_mail_spool == NULL) {
8133 variable_substitute(MAIL_FILE, buf, 256);
8135 if (buf[0] != '\0') {
8136 current_mail_spool = strdup(buf);
8141 /* handle other command line arguments */
8143 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8144 || defined(__NetBSD__)
8145 optind = optreset = 1;
8150 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8151 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8152 "kvm_open")) == NULL) {
8153 CRIT_ERR("cannot read kvm");
8158 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8166 fork_to_background = 1;
8171 set_first_font(optarg);
8174 text_alignment = string_to_alignment(optarg);
8192 text = strdup(optarg);
8193 convert_escapes(text);
8197 update_interval = strtod(optarg, 0);
8198 if (info.music_player_interval == 0) {
8199 // default to update_interval
8200 info.music_player_interval = update_interval;
8205 total_run_times = strtod(optarg, 0);
8209 gap_x = atoi(optarg);
8213 gap_y = atoi(optarg);
8227 /* generate text and get initial size */
8228 extract_variable_text(text);
8234 if (fork_to_background) {
8239 ERR("Conky: couldn't fork() to background: %s",
8246 fprintf(stderr, "\n");
8251 /* parent process */
8252 fprintf(stderr, "Conky: forked to background, pid is %d\n",
8261 update_text_area(); /* to get initial size of the window */
8263 init_window(own_window, text_width + border_margin * 2 + 1,
8264 text_height + border_margin * 2 + 1, set_transparent, background_colour,
8268 update_text_area(); /* to position text/window on screen */
8273 if (own_window && !fixed_pos) {
8274 XMoveWindow(display, window.window, window.x, window.y);
8277 set_transparent_background(window.window);
8287 /* Set signal handlers */
8288 act.sa_handler = signal_handler;
8289 sigemptyset(&act.sa_mask);
8292 act.sa_flags |= SA_RESTART;
8295 if (sigaction(SIGINT, &act, &oact) < 0
8296 || sigaction(SIGUSR1, &act, &oact) < 0
8297 || sigaction(SIGTERM, &act, &oact) < 0) {
8298 ERR("error setting signal handler: %s", strerror(errno));
8301 /* *************** *
8303 * *************** */
8306 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8313 void signal_handler(int sig)
8315 /* signal handler is light as a feather, as it should be.
8316 * we will poll g_signal_pending with each loop of conky
8317 * and do any signal processing there, NOT here. */
8318 g_signal_pending = sig;