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-2009 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/>.
29 #include "text_object.h"
44 #include <sys/param.h>
45 #ifdef HAVE_SYS_INOTIFY_H
46 #include <sys/inotify.h>
47 #endif /* HAVE_SYS_INOTIFY_H */
50 #include <X11/Xutil.h>
52 #include <X11/extensions/Xdamage.h>
58 #include <sys/types.h>
60 #include <netinet/in.h>
79 #include "temphelper.h"
83 /* check for OS and include appropriate headers */
84 #if defined(__linux__)
86 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
88 #elif defined(__OpenBSD__)
92 #if defined(__FreeBSD_kernel__)
96 /* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
97 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
98 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
99 int apm_getinfo(int fd, apm_info_t aip);
100 char *get_apm_adapter(void);
101 char *get_apm_battery_life(void);
102 char *get_apm_battery_time(void);
110 #include "defconfig.h"
111 #include "conf_cookie.h"
115 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
118 #define MAIL_FILE "$MAIL"
119 #define MAX_IF_BLOCK_DEPTH 5
121 //#define SIGNAL_BLOCKING
122 #undef SIGNAL_BLOCKING
124 /* debugging level, used by logging.h */
125 int global_debug_level = 0;
127 /* two strings for internal use */
128 static char *tmpstring1, *tmpstring2;
130 /* variables holding various config settings */
132 int format_human_readable;
139 int top_cpu, top_mem, top_time;
143 static unsigned int top_name_width = 15;
145 static int extra_newline;
146 enum x_initialiser_state x_initialised = NO;
147 static volatile int g_signal_pending;
148 /* Update interval */
149 double update_interval;
150 void *global_cpu = NULL;
155 /* prototypes for internally used functions */
156 static void signal_handler(int);
157 static void print_version(void) __attribute__((noreturn));
158 static void reload_config(void);
159 static void generate_text_internal(char *, int, struct text_object,
160 struct information *);
161 static int extract_variable_text_internal(struct text_object *,
164 static void print_version(void)
166 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
168 printf("\nCompiled in features:\n\n"
169 "System config file: "SYSTEM_CONFIG_FILE"\n"
170 "Package library path: "PACKAGE_LIBDIR"\n\n"
174 " * Xdamage extension\n"
175 # endif /* HAVE_XDAMAGE */
177 " * XDBE (double buffer extension)\n"
178 # endif /* HAVE_XDBE */
183 "\n Music detection:\n"
186 #endif /* AUDACIOUS */
202 #endif /* HAVE_OPENMP */
209 #ifdef TCP_PORT_MONITOR
211 #endif /* TCP_PORT_MONITOR */
214 #endif /* HAVE_CURL */
219 " * Weather (NOAA)\n"
221 " * Weather (XOAP)\n"
226 #endif /* HAVE_IWLIB */
228 " * support for IBM/Lenovo notebooks\n"
238 #endif /* CONFIG_OUTPUT */
243 " * ALSA mixer support\n"
244 #endif /* MIXER_IS_ALSA */
254 #ifdef HAVE_LUA_CAIRO
256 #endif /* HAVE_LUA_CAIRO */
257 #ifdef HAVE_LUA_IMLIB2
260 #endif /* HAVE_LUA */
266 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
271 static void X11_create_window(void);
272 static void X11_initialisation(void);
274 struct _x11_stuff_s {
278 XserverRegion region2, part;
279 int event_base, error_base;
285 static int text_start_x, text_start_y; /* text start position in window */
286 static int text_width, text_height;
301 /* display to connect to */
302 static char *disp = NULL;
306 /* struct that has all info to be shared between
307 * instances of the same text object */
308 struct information info;
310 /* path to config file */
311 char *current_config;
313 /* set to 1 if you want all text to be in uppercase */
314 static unsigned int stuff_in_uppercase;
316 /* Run how many times? */
317 static unsigned long total_run_times;
320 static int fork_to_background;
322 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
324 /* filenames for output */
325 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
326 char *append_file = NULL; FILE *append_fpointer = NULL;
328 /* xoap suffix for weather from weather.com */
330 static char *xoap = NULL;
335 static int show_graph_scale;
336 static int show_graph_range;
338 /* Position on the screen */
339 static int text_alignment;
340 static int gap_x, gap_y;
343 static int draw_borders;
344 static int draw_graph_borders;
345 static int stippled_borders;
347 static int draw_shades, draw_outline;
349 static long default_fg_color, default_bg_color, default_out_color;
351 /* create own window or draw stuff to root? */
352 static int set_transparent = 0;
355 static int own_window = 0;
356 static int background_colour = 0;
358 /* fixed size/pos is set if wm/user changes them */
359 static int fixed_size = 0, fixed_pos = 0;
362 static int minimum_width, minimum_height;
363 static int maximum_width;
368 static int sensor_device;
371 static long color0, color1, color2, color3, color4, color5, color6, color7,
374 #define MAX_TEMPLATES 10
375 static char *template[MAX_TEMPLATES];
377 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
378 unsigned int max_user_text;
380 /* maximum size of individual text buffers, ie $exec buffer size */
381 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
384 #define CODEPAGE_LENGTH 20
386 long iconv_count = 0;
387 char iconv_converting;
388 static iconv_t **iconv_cd = 0;
390 int register_iconv(iconv_t *new_iconv)
392 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
394 CRIT_ERR(NULL, NULL, "Out of memory");
396 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
397 if (!iconv_cd[iconv_count]) {
398 CRIT_ERR(NULL, NULL, "Out of memory");
400 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
405 void free_iconv(void)
410 for (i = 0; i < iconv_count; i++) {
412 iconv_close(*iconv_cd[i]);
426 /* no buffers in used memory? */
429 /* pad percentages to decimals? */
430 static int pad_percents = 0;
432 static char *global_text = 0;
433 long global_text_lines;
435 static int total_updates;
436 static int updatereset;
438 int check_contains(char *f, char *s)
441 FILE *where = open_file(f, 0);
446 while (fgets(buf1, 256, where)) {
447 if (strstr(buf1, s)) {
454 ERR("Could not open the file");
459 #define SECRIT_MULTILINE_CHAR '\x02'
463 static inline int calc_text_width(const char *s, int l)
465 if ((output_methods & TO_X) == 0) {
473 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
474 (const FcChar8 *) s, l, &gi);
476 XftTextExtents8(display, fonts[selected_font].xftfont,
477 (const FcChar8 *) s, l, &gi);
483 return XTextWidth(fonts[selected_font].font, s, l);
488 /* formatted text to render on screen, generated in generate_text(),
489 * drawn in draw_stuff() */
491 static char *text_buffer;
493 /* quite boring functions */
495 static inline void for_each_line(char *b, int f(char *, int))
498 int special_index = 0; /* specials index */
500 for (ps = b, pe = b; *pe; pe++) {
503 special_index = f(ps, special_index);
510 f(ps, special_index);
514 static void convert_escapes(char *buf)
516 char *p = buf, *s = buf;
523 } else if (*s == '\\') {
534 /* Prints anything normally printed with snprintf according to the current value
535 * of use_spacer. Actually slightly more flexible than snprintf, as you can
536 * safely specify the destination buffer as one of your inputs. */
537 int spaced_print(char *buf, int size, const char *format, int width, ...)
546 tempbuf = malloc(size * sizeof(char));
548 // Passes the varargs along to vsnprintf
549 va_start(argp, width);
550 vsnprintf(tempbuf, size, format, argp);
553 switch (use_spacer) {
555 len = snprintf(buf, size, "%s", tempbuf);
558 len = snprintf(buf, size, "%*s", width, tempbuf);
561 len = snprintf(buf, size, "%-*s", width, tempbuf);
568 /* print percentage values
570 * - i.e., unsigned values between 0 and 100
571 * - respect the value of pad_percents */
572 static int percent_print(char *buf, int size, unsigned value)
574 return spaced_print(buf, size, "%u", pad_percents, value);
577 /* converts from bytes to human readable format (K, M, G, T)
579 * The algorithm always divides by 1024, as unit-conversion of byte
580 * counts suggests. But for output length determination we need to
581 * compare with 1000 here, as we print in decimal form. */
582 static void human_readable(long long num, char *buf, int size)
584 const char **suffix = suffixes;
590 /* Possibly just output as usual, for example for stdout usage */
591 if (!format_human_readable) {
592 spaced_print(buf, size, "%d", 6, round_to_int(num));
603 if (llabs(num) < 1000LL) {
604 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
608 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
616 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
618 * The goal is to always have a significance of 3, by
619 * adjusting the decimal part of the number. Sample output:
623 * so the point of alignment resides between number and unit. The
624 * upside of this is that there is minimal padding necessary, though
625 * there should be a way to make alignment take place at the decimal
626 * dot (then with fixed width decimal part).
628 * Note the repdigits below: when given a precision value, printf()
629 * rounds the float to it, not just cuts off the remaining digits. So
630 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
631 * printed with a precision of 0. Yay. */
633 precision = 0; /* print 100-999 without decimal part */
635 precision = 1; /* print 10-99 with one decimal place */
637 precision = 2; /* print 0-9 with two decimal places */
639 spaced_print(buf, size, format, width, precision, fnum, *suffix);
642 /* global object list root element */
643 static struct text_object global_root_object;
645 static inline void read_exec(const char *data, char *buf, const int size)
647 FILE *fp = popen(data, "r");
648 int length = fread(buf, 1, size, fp);
652 if (length > 0 && buf[length - 1] == '\n') {
653 buf[length - 1] = '\0';
657 void *threaded_exec(void *) __attribute__((noreturn));
659 void *threaded_exec(void *arg)
662 struct text_object *obj = (struct text_object *)arg;
665 buff = malloc(text_buffer_size);
666 read_exec(obj->data.texeci.cmd, buff,
675 timed_thread_lock(obj->data.texeci.p_timed_thread);
676 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
677 timed_thread_unlock(obj->data.texeci.p_timed_thread);
679 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
680 timed_thread_exit(obj->data.texeci.p_timed_thread);
686 static struct text_object *new_text_object_internal(void)
688 struct text_object *obj = malloc(sizeof(struct text_object));
689 memset(obj, 0, sizeof(struct text_object));
694 * Frees the list of text objects root points to. When internal = 1, it won't
695 * free global objects.
697 static void free_text_objects(struct text_object *root, int internal)
699 struct text_object *obj;
705 #define data obj->data
706 for (obj = root->prev; obj; obj = root->prev) {
707 root->prev = obj->prev;
713 #endif /* !__OpenBSD__ */
718 close(data.sysfs.fd);
720 #endif /* __linux__ */
722 free(data.read_tcp.host);
729 free(data.tztime.tz);
730 free(data.tztime.fmt);
733 free(data.mboxscan.args);
734 free(data.mboxscan.output);
739 case OBJ_unseen_mails:
740 case OBJ_flagged_mails:
741 case OBJ_unflagged_mails:
742 case OBJ_forwarded_mails:
743 case OBJ_unforwarded_mails:
744 case OBJ_replied_mails:
745 case OBJ_unreplied_mails:
746 case OBJ_draft_mails:
747 case OBJ_trashed_mails:
748 free(data.local_mail.box);
750 case OBJ_imap_unseen:
755 case OBJ_imap_messages:
760 case OBJ_pop3_unseen:
772 free_text_objects(obj->sub, 1);
775 case OBJ_if_existing:
778 free(data.ifblock.s);
779 free(data.ifblock.str);
782 free(data.tail.logfile);
783 free(data.tail.buffer);
799 case OBJ_iconv_start:
804 case OBJ_disk_protect:
808 free(data.ifblock.s);
809 free(data.ifblock.str);
812 if (info.gw_info.iface) {
813 free(info.gw_info.iface);
814 info.gw_info.iface = 0;
816 if (info.gw_info.ip) {
817 free(info.gw_info.ip);
821 case OBJ_ioscheduler:
826 #if (defined(__FreeBSD__) || defined(__linux__))
828 free(data.ifblock.s);
829 free(data.ifblock.str);
833 case OBJ_xmms2_artist:
834 if (info.xmms2.artist) {
835 free(info.xmms2.artist);
836 info.xmms2.artist = 0;
839 case OBJ_xmms2_album:
840 if (info.xmms2.album) {
841 free(info.xmms2.album);
842 info.xmms2.album = 0;
845 case OBJ_xmms2_title:
846 if (info.xmms2.title) {
847 free(info.xmms2.title);
848 info.xmms2.title = 0;
851 case OBJ_xmms2_genre:
852 if (info.xmms2.genre) {
853 free(info.xmms2.genre);
854 info.xmms2.genre = 0;
857 case OBJ_xmms2_comment:
858 if (info.xmms2.comment) {
859 free(info.xmms2.comment);
860 info.xmms2.comment = 0;
864 if (info.xmms2.url) {
865 free(info.xmms2.url);
870 if (info.xmms2.date) {
871 free(info.xmms2.date);
875 case OBJ_xmms2_status:
876 if (info.xmms2.status) {
877 free(info.xmms2.status);
878 info.xmms2.status = 0;
881 case OBJ_xmms2_playlist:
882 if (info.xmms2.playlist) {
883 free(info.xmms2.playlist);
884 info.xmms2.playlist = 0;
887 case OBJ_xmms2_smart:
888 if (info.xmms2.artist) {
889 free(info.xmms2.artist);
890 info.xmms2.artist = 0;
892 if (info.xmms2.title) {
893 free(info.xmms2.title);
894 info.xmms2.title = 0;
896 if (info.xmms2.url) {
897 free(info.xmms2.url);
904 case OBJ_bmpx_artist:
908 case OBJ_bmpx_bitrate:
923 free(data.rss.action);
928 free(data.weather.uri);
929 free(data.weather.data_type);
942 #endif /* HAVE_LUA */
949 case OBJ_battery_short:
952 case OBJ_battery_time:
955 #endif /* !__OpenBSD__ */
963 free(data.execi.cmd);
964 free(data.execi.buffer);
967 if (data.texeci.p_timed_thread) timed_thread_destroy(data.texeci.p_timed_thread, &data.texeci.p_timed_thread);
968 free(data.texeci.cmd);
969 free(data.texeci.buffer);
980 if (info.first_process && !internal) {
981 free_all_processes();
982 info.first_process = NULL;
984 if (data.top.s) free(data.top.s);
988 free(data.hddtemp.dev);
989 free(data.hddtemp.addr);
990 if (data.hddtemp.temp)
991 free(data.hddtemp.temp);
994 case OBJ_entropy_avail:
995 case OBJ_entropy_perc:
996 case OBJ_entropy_poolsize:
997 case OBJ_entropy_bar:
1000 if (info.users.names) {
1001 free(info.users.names);
1002 info.users.names = 0;
1005 case OBJ_user_terms:
1006 if (info.users.terms) {
1007 free(info.users.terms);
1008 info.users.terms = 0;
1011 case OBJ_user_times:
1012 if (info.users.times) {
1013 free(info.users.times);
1014 info.users.times = 0;
1019 case OBJ_smapi_bat_perc:
1020 case OBJ_smapi_bat_temp:
1021 case OBJ_smapi_bat_power:
1024 case OBJ_if_smapi_bat_installed:
1025 free(data.ifblock.s);
1026 free(data.ifblock.str);
1035 case OBJ_mpd_artist:
1037 case OBJ_mpd_random:
1038 case OBJ_mpd_repeat:
1040 case OBJ_mpd_bitrate:
1041 case OBJ_mpd_status:
1043 case OBJ_mpd_elapsed:
1044 case OBJ_mpd_length:
1048 case OBJ_mpd_percent:
1050 case OBJ_if_mpd_playing:
1058 case OBJ_moc_artist:
1061 case OBJ_moc_totaltime:
1062 case OBJ_moc_timeleft:
1063 case OBJ_moc_curtime:
1064 case OBJ_moc_bitrate:
1071 free_text_objects(obj->sub, 1);
1075 free(data.scroll.text);
1076 free_text_objects(obj->sub, 1);
1080 free(data.combine.left);
1081 free(data.combine.seperation);
1082 free(data.combine.right);
1083 free_text_objects(obj->sub, 1);
1088 case OBJ_apcupsd_name:
1089 case OBJ_apcupsd_model:
1090 case OBJ_apcupsd_upsmode:
1091 case OBJ_apcupsd_cable:
1092 case OBJ_apcupsd_status:
1093 case OBJ_apcupsd_linev:
1094 case OBJ_apcupsd_load:
1095 case OBJ_apcupsd_loadbar:
1097 case OBJ_apcupsd_loadgraph:
1098 case OBJ_apcupsd_loadgauge:
1100 case OBJ_apcupsd_charge:
1101 case OBJ_apcupsd_timeleft:
1102 case OBJ_apcupsd_temp:
1103 case OBJ_apcupsd_lastxfer:
1105 #endif /* APCUPSD */
1108 case OBJ_desktop_number:
1109 case OBJ_desktop_name:
1110 if(info.x11.desktop.name) {
1111 free(info.x11.desktop.name);
1112 info.x11.desktop.name = NULL;
1114 if(info.x11.desktop.all_names) {
1115 free(info.x11.desktop.all_names);
1116 info.x11.desktop.all_names = NULL;
1127 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1132 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1133 *a = mixer_init(buf1);
1134 scan_bar(arg + n, w, h);
1136 *a = mixer_init(NULL);
1137 scan_bar(arg, w, h);
1142 /* strip a leading /dev/ if any, following symlinks first
1144 * BEWARE: this function returns a pointer to static content
1145 * which gets overwritten in consecutive calls. I.e.:
1146 * this function is NOT reentrant.
1148 static const char *dev_name(const char *path)
1150 static char buf[255]; /* should be enough for pathnames */
1156 #define DEV_NAME(x) \
1157 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1158 if ((buflen = readlink(path, buf, 254)) == -1)
1159 return DEV_NAME(path);
1161 return DEV_NAME(buf);
1165 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1170 if (obj->data.top.was_parsed) {
1173 obj->data.top.was_parsed = 1;
1175 if (arg && !obj->data.top.s) {
1176 obj->data.top.s = strndup(arg, text_buffer_size);
1179 need_mask |= (1 << INFO_TOP);
1182 obj->type = OBJ_top;
1184 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1185 obj->type = OBJ_top_mem;
1187 } else if (strcmp(&s[3], "_time") == EQUAL) {
1188 obj->type = OBJ_top_time;
1191 } else if (strcmp(&s[3], "_io") == EQUAL) {
1192 obj->type = OBJ_top_io;
1197 ERR("Must be top, top_mem, top_time or top_io");
1199 ERR("Must be top, top_mem or top_time");
1205 ERR("top needs arguments");
1209 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1210 if (strcmp(buf, "name") == EQUAL) {
1211 obj->data.top.type = TOP_NAME;
1212 } else if (strcmp(buf, "cpu") == EQUAL) {
1213 obj->data.top.type = TOP_CPU;
1214 } else if (strcmp(buf, "pid") == EQUAL) {
1215 obj->data.top.type = TOP_PID;
1216 } else if (strcmp(buf, "mem") == EQUAL) {
1217 obj->data.top.type = TOP_MEM;
1218 } else if (strcmp(buf, "time") == EQUAL) {
1219 obj->data.top.type = TOP_TIME;
1220 } else if (strcmp(buf, "mem_res") == EQUAL) {
1221 obj->data.top.type = TOP_MEM_RES;
1222 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1223 obj->data.top.type = TOP_MEM_VSIZE;
1225 } else if (strcmp(buf, "io_read") == EQUAL) {
1226 obj->data.top.type = TOP_READ_BYTES;
1227 } else if (strcmp(buf, "io_write") == EQUAL) {
1228 obj->data.top.type = TOP_WRITE_BYTES;
1229 } else if (strcmp(buf, "io_perc") == EQUAL) {
1230 obj->data.top.type = TOP_IO_PERC;
1233 ERR("invalid type arg for top");
1235 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, "
1236 "io_read, io_write, io_perc");
1238 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1242 if (n < 1 || n > 10) {
1243 ERR("invalid num arg for top. Must be between 1 and 10.");
1246 obj->data.top.num = n - 1;
1249 ERR("invalid argument count for top");
1255 long current_text_color;
1257 /* construct_text_object() creates a new text_object */
1258 static struct text_object *construct_text_object(const char *s,
1259 const char *arg, long line, void **ifblock_opaque, void *free_at_crash)
1261 // struct text_object *obj = new_text_object();
1262 struct text_object *obj = new_text_object_internal();
1266 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1267 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1268 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1269 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1270 obj_be_ifblock_if(ifblock_opaque, obj); {
1271 #define END } } else
1273 #define SIZE_DEFAULTS(arg) { \
1274 obj->a = default_##arg##_width; \
1275 obj->b = default_##arg##_height; \
1280 obj->type = OBJ_color;
1281 obj->data.l = get_x11_color(s);
1285 OBJ(freq, INFO_FREQ)
1288 obj->data.i = open_acpi_temperature(arg);
1289 END OBJ(acpiacadapter, 0)
1290 END OBJ(freq, INFO_FREQ)
1291 #endif /* !__OpenBSD__ */
1293 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1294 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1295 obj->data.cpu_index = 1;
1296 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1297 "Displaying the clock for CPU 1."); */
1299 obj->data.cpu_index = atoi(&arg[0]);
1302 END OBJ(freq_g, INFO_FREQ)
1304 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1305 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1306 obj->data.cpu_index = 1;
1307 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1308 "CPUs! Displaying the clock for CPU 1."); */
1310 obj->data.cpu_index = atoi(&arg[0]);
1313 END OBJ(read_tcp, 0)
1315 obj->data.read_tcp.host = malloc(text_buffer_size);
1316 sscanf(arg, "%s", obj->data.read_tcp.host);
1317 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
1318 if(obj->data.read_tcp.port == 0) {
1319 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
1320 strcpy(obj->data.read_tcp.host,"localhost");
1322 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
1323 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
1324 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
1327 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
1329 #if defined(__linux__)
1330 END OBJ(voltage_mv, 0)
1332 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1333 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1334 obj->data.cpu_index = 1;
1335 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1336 "CPUs! Displaying voltage for CPU 1."); */
1338 obj->data.cpu_index = atoi(&arg[0]);
1341 END OBJ(voltage_v, 0)
1343 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1344 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1345 obj->data.cpu_index = 1;
1346 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1347 "CPUs! Displaying voltage for CPU 1."); */
1349 obj->data.cpu_index = atoi(&arg[0]);
1354 END OBJ(wireless_essid, INFO_NET)
1356 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1358 // default to DEFAULTNETDEV
1359 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1360 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1363 END OBJ(wireless_mode, INFO_NET)
1365 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1367 // default to DEFAULTNETDEV
1368 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1369 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1372 END OBJ(wireless_bitrate, INFO_NET)
1374 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1376 // default to DEFAULTNETDEV
1377 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1378 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1381 END OBJ(wireless_ap, INFO_NET)
1383 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1385 // default to DEFAULTNETDEV
1386 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1387 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1390 END OBJ(wireless_link_qual, INFO_NET)
1392 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1394 // default to DEFAULTNETDEV
1395 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1396 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1399 END OBJ(wireless_link_qual_max, INFO_NET)
1401 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1403 // default to DEFAULTNETDEV
1404 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1405 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1408 END OBJ(wireless_link_qual_perc, INFO_NET)
1410 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1412 // default to DEFAULTNETDEV
1413 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1414 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1417 END OBJ(wireless_link_bar, INFO_NET)
1420 arg = scan_bar(arg, &obj->a, &obj->b);
1421 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1423 // default to DEFAULTNETDEV
1424 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1425 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1428 #endif /* HAVE_IWLIB */
1430 #endif /* __linux__ */
1438 sscanf(arg, "%63s", bat);
1440 strcpy(bat, "BAT0");
1442 obj->data.s = strndup(bat, text_buffer_size);
1443 END OBJ(battery_short, 0)
1447 sscanf(arg, "%63s", bat);
1449 strcpy(bat, "BAT0");
1451 obj->data.s = strndup(bat, text_buffer_size);
1452 END OBJ(battery_time, 0)
1456 sscanf(arg, "%63s", bat);
1458 strcpy(bat, "BAT0");
1460 obj->data.s = strndup(bat, text_buffer_size);
1461 END OBJ(battery_percent, 0)
1465 sscanf(arg, "%63s", bat);
1467 strcpy(bat, "BAT0");
1469 obj->data.s = strndup(bat, text_buffer_size);
1470 END OBJ(battery_bar, 0)
1475 arg = scan_bar(arg, &obj->a, &obj->b);
1476 sscanf(arg, "%63s", bat);
1478 strcpy(bat, "BAT0");
1480 obj->data.s = strndup(bat, text_buffer_size);
1481 #endif /* !__OpenBSD__ */
1483 #if defined(__linux__)
1484 END OBJ(disk_protect, 0)
1486 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1488 CRIT_ERR(obj, free_at_crash, "disk_protect needs an argument");
1489 END OBJ(i8k_version, INFO_I8K)
1490 END OBJ(i8k_bios, INFO_I8K)
1491 END OBJ(i8k_serial, INFO_I8K)
1492 END OBJ(i8k_cpu_temp, INFO_I8K)
1493 END OBJ(i8k_left_fan_status, INFO_I8K)
1494 END OBJ(i8k_right_fan_status, INFO_I8K)
1495 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1496 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1497 END OBJ(i8k_ac_status, INFO_I8K)
1498 END OBJ(i8k_buttons_status, INFO_I8K)
1501 END OBJ(ibm_temps, 0)
1503 CRIT_ERR(obj, free_at_crash, "ibm_temps: needs an argument");
1505 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1506 obj->data.sensor = 0;
1507 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1508 "Using 0 (CPU temp sensor).");
1510 obj->data.sensor = atoi(&arg[0]);
1511 END OBJ(ibm_volume, 0)
1512 END OBJ(ibm_brightness, 0)
1514 /* information from sony_laptop kernel module
1515 * /sys/devices/platform/sony-laptop */
1516 END OBJ(sony_fanspeed, 0)
1517 END OBJ_IF(if_gw, INFO_GW)
1518 END OBJ(ioscheduler, 0)
1520 CRIT_ERR(obj, free_at_crash, "get_ioscheduler needs an argument (e.g. hda)");
1523 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1524 END OBJ(laptop_mode, 0)
1525 END OBJ(pb_battery, 0)
1526 if (arg && strcmp(arg, "status") == EQUAL) {
1527 obj->data.i = PB_BATT_STATUS;
1528 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1529 obj->data.i = PB_BATT_PERCENT;
1530 } else if (arg && strcmp(arg, "time") == EQUAL) {
1531 obj->data.i = PB_BATT_TIME;
1533 ERR("pb_battery: needs one argument: status, percent or time");
1538 #endif /* __linux__ */
1539 #if (defined(__FreeBSD__) || defined(__linux__))
1540 END OBJ_IF(if_up, 0)
1542 ERR("if_up needs an argument");
1543 obj->data.ifblock.s = 0;
1545 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1548 #if defined(__OpenBSD__)
1549 END OBJ(obsd_sensors_temp, 0)
1551 CRIT_ERR(obj, free_at_crash, "obsd_sensors_temp: needs an argument");
1553 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1554 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1555 obj->data.sensor = 0;
1556 ERR("Invalid temperature sensor number!");
1558 obj->data.sensor = atoi(&arg[0]);
1559 END OBJ(obsd_sensors_fan, 0)
1561 CRIT_ERR(obj, free_at_crash, "obsd_sensors_fan: needs 2 arguments (device and sensor "
1564 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1565 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1566 obj->data.sensor = 0;
1567 ERR("Invalid fan sensor number!");
1569 obj->data.sensor = atoi(&arg[0]);
1570 END OBJ(obsd_sensors_volt, 0)
1572 CRIT_ERR(obj, free_at_crash, "obsd_sensors_volt: needs 2 arguments (device and sensor "
1575 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1576 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1577 obj->data.sensor = 0;
1578 ERR("Invalid voltage sensor number!");
1580 obj->data.sensor = atoi(&arg[0]);
1581 END OBJ(obsd_vendor, 0)
1582 END OBJ(obsd_product, 0)
1583 #endif /* __OpenBSD__ */
1584 END OBJ(buffers, INFO_BUFFERS)
1585 END OBJ(cached, INFO_BUFFERS)
1586 #define SCAN_CPU(__arg, __var) { \
1588 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1589 __arg += __offset; \
1593 END OBJ(cpu, INFO_CPU)
1594 SCAN_CPU(arg, obj->data.cpu_index);
1595 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1597 END OBJ(cpugauge, INFO_CPU)
1598 SIZE_DEFAULTS(gauge);
1599 SCAN_CPU(arg, obj->data.cpu_index);
1600 scan_gauge(arg, &obj->a, &obj->b);
1601 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1603 END OBJ(cpubar, INFO_CPU)
1605 SCAN_CPU(arg, obj->data.cpu_index);
1606 scan_bar(arg, &obj->a, &obj->b);
1607 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1609 END OBJ(cpugraph, INFO_CPU)
1611 SIZE_DEFAULTS(graph);
1612 SCAN_CPU(arg, obj->data.cpu_index);
1613 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1614 &obj->e, &obj->char_a, &obj->char_b);
1615 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1617 END OBJ(loadgraph, INFO_LOADAVG)
1619 SIZE_DEFAULTS(graph);
1620 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1621 &obj->e, &obj->char_a, &obj->char_b);
1625 r = sscanf(arg, "%d", &a);
1627 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1631 END OBJ(diskio, INFO_DISKIO)
1632 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1633 END OBJ(diskio_read, INFO_DISKIO)
1634 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1635 END OBJ(diskio_write, INFO_DISKIO)
1636 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1638 END OBJ(diskiograph, INFO_DISKIO)
1640 SIZE_DEFAULTS(graph);
1641 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1642 &obj->e, &obj->char_a, &obj->char_b);
1644 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1646 END OBJ(diskiograph_read, INFO_DISKIO)
1648 SIZE_DEFAULTS(graph);
1649 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1650 &obj->e, &obj->char_a, &obj->char_b);
1652 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1654 END OBJ(diskiograph_write, INFO_DISKIO)
1656 SIZE_DEFAULTS(graph);
1657 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1658 &obj->e, &obj->char_a, &obj->char_b);
1660 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1665 if (output_methods & TO_X) {
1666 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1667 current_text_color = obj->data.l;
1671 obj->data.l = color0;
1672 current_text_color = obj->data.l;
1674 obj->data.l = color1;
1675 current_text_color = obj->data.l;
1677 obj->data.l = color2;
1678 current_text_color = obj->data.l;
1680 obj->data.l = color3;
1681 current_text_color = obj->data.l;
1683 obj->data.l = color4;
1684 current_text_color = obj->data.l;
1686 obj->data.l = color5;
1687 current_text_color = obj->data.l;
1689 obj->data.l = color6;
1690 current_text_color = obj->data.l;
1692 obj->data.l = color7;
1693 current_text_color = obj->data.l;
1695 obj->data.l = color8;
1696 current_text_color = obj->data.l;
1698 obj->data.l = color9;
1699 current_text_color = obj->data.l;
1702 obj->data.s = scan_font(arg);
1704 END OBJ(conky_version, 0)
1705 END OBJ(conky_build_date, 0)
1706 END OBJ(conky_build_arch, 0)
1707 END OBJ(downspeed, INFO_NET)
1709 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1711 // default to DEFAULTNETDEV
1712 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1713 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1716 END OBJ(downspeedf, INFO_NET)
1718 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1720 // default to DEFAULTNETDEV
1721 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1722 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1726 END OBJ(downspeedgraph, INFO_NET)
1728 SIZE_DEFAULTS(graph);
1729 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1730 &obj->e, &obj->char_a, &obj->char_b);
1732 // default to DEFAULTNETDEV
1733 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1734 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1738 obj_be_ifblock_else(ifblock_opaque, obj);
1740 obj_be_ifblock_endif(ifblock_opaque, obj);
1742 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1744 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1747 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1749 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1752 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1754 END OBJ(execgauge, 0)
1755 SIZE_DEFAULTS(gauge);
1756 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1757 END OBJ(execgraph, 0)
1758 SIZE_DEFAULTS(graph);
1759 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1761 END OBJ(execibar, 0)
1765 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1768 ERR("${execibar <interval> command}");
1769 obj->type = OBJ_text;
1770 snprintf(buf, 256, "${%s}", s);
1771 obj->data.s = strndup(buf, text_buffer_size);
1773 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1776 END OBJ(execigraph, 0)
1778 SIZE_DEFAULTS(graph);
1780 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1783 ERR("${execigraph <interval> command}");
1784 obj->type = OBJ_text;
1785 snprintf(buf, 256, "${%s}", s);
1786 obj->data.s = strndup(buf, text_buffer_size);
1788 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1790 END OBJ(execigauge, 0)
1792 SIZE_DEFAULTS(gauge);
1794 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1797 ERR("${execigauge <interval> command}");
1798 obj->type = OBJ_text;
1799 snprintf(buf, 256, "${%s}", s);
1800 obj->data.s = strndup(buf, text_buffer_size);
1802 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1808 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1811 ERR("${execi <interval> command}");
1812 obj->type = OBJ_text;
1813 snprintf(buf, 256, "${%s}", s);
1814 obj->data.s = strndup(buf, text_buffer_size);
1816 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1817 obj->data.execi.buffer = malloc(text_buffer_size);
1822 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1825 ERR("${execi <interval> command}");
1826 obj->type = OBJ_text;
1827 snprintf(buf, 256, "${%s}", s);
1828 obj->data.s = strndup(buf, text_buffer_size);
1830 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1831 obj->data.execi.buffer = malloc(text_buffer_size);
1836 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1839 ERR("${texeci <interval> command}");
1840 obj->type = OBJ_text;
1841 snprintf(buf, 256, "${%s}", s);
1842 obj->data.s = strndup(buf, text_buffer_size);
1844 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1845 obj->data.texeci.buffer = malloc(text_buffer_size);
1847 obj->data.texeci.p_timed_thread = NULL;
1848 END OBJ(pre_exec, 0)
1849 obj->type = OBJ_text;
1853 read_exec(arg, buf, sizeof(buf));
1854 obj->data.s = strndup(buf, text_buffer_size);
1856 obj->data.s = strndup("", text_buffer_size);
1859 END OBJ(fs_bar, INFO_FS)
1861 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1863 while (isspace(*arg)) {
1872 obj->data.fsbar.fs = prepare_fs_stat(arg);
1873 END OBJ(fs_bar_free, INFO_FS)
1875 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1877 while (isspace(*arg)) {
1887 obj->data.fsbar.fs = prepare_fs_stat(arg);
1888 END OBJ(fs_free, INFO_FS)
1892 obj->data.fs = prepare_fs_stat(arg);
1893 END OBJ(fs_used_perc, INFO_FS)
1897 obj->data.fs = prepare_fs_stat(arg);
1898 END OBJ(fs_free_perc, INFO_FS)
1902 obj->data.fs = prepare_fs_stat(arg);
1903 END OBJ(fs_size, INFO_FS)
1907 obj->data.fs = prepare_fs_stat(arg);
1908 END OBJ(fs_type, INFO_FS)
1912 obj->data.fs = prepare_fs_stat(arg);
1913 END OBJ(fs_used, INFO_FS)
1917 obj->data.fs = prepare_fs_stat(arg);
1919 obj->data.i = arg ? atoi(arg) : 1;
1920 END OBJ(nameserver, INFO_DNS)
1921 obj->data.i = arg ? atoi(arg) : 0;
1923 obj->data.i = arg ? atoi(arg) : 1;
1925 obj->data.i = arg ? atoi(arg) : 1;
1929 ERR("goto needs arguments");
1930 obj->type = OBJ_text;
1931 obj->data.s = strndup("${goto}", text_buffer_size);
1935 obj->data.i = atoi(arg);
1941 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1942 sscanf(arg, "%d", &b);
1948 obj->data.pair.a = a;
1949 obj->data.pair.b = b;
1952 END OBJ(i2c, INFO_SYSFS)
1953 char buf1[64], buf2[64];
1954 float factor, offset;
1958 ERR("i2c needs arguments");
1959 obj->type = OBJ_text;
1960 // obj->data.s = strndup("${i2c}", text_buffer_size);
1964 #define HWMON_RESET() {\
1969 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1970 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1971 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1972 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1975 ERR("i2c failed to parse arguments");
1976 obj->type = OBJ_text;
1979 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1980 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1981 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1982 strncpy(obj->data.sysfs.type, buf2, 63);
1983 obj->data.sysfs.factor = factor;
1984 obj->data.sysfs.offset = offset;
1986 END OBJ(platform, INFO_SYSFS)
1987 char buf1[64], buf2[64];
1988 float factor, offset;
1992 ERR("platform needs arguments");
1993 obj->type = OBJ_text;
1997 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1998 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1999 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
2000 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
2003 ERR("platform failed to parse arguments");
2004 obj->type = OBJ_text;
2007 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
2008 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
2009 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2010 strncpy(obj->data.sysfs.type, buf2, 63);
2011 obj->data.sysfs.factor = factor;
2012 obj->data.sysfs.offset = offset;
2014 END OBJ(hwmon, INFO_SYSFS)
2015 char buf1[64], buf2[64];
2016 float factor, offset;
2020 ERR("hwmon needs argumanets");
2021 obj->type = OBJ_text;
2025 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
2026 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
2027 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
2028 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
2033 ERR("hwmon failed to parse arguments");
2034 obj->type = OBJ_text;
2037 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
2038 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
2039 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2040 strncpy(obj->data.sysfs.type, buf2, 63);
2041 obj->data.sysfs.factor = factor;
2042 obj->data.sysfs.offset = offset;
2044 #endif /* !__OpenBSD__ */
2047 /* we have four different types of top (top, top_mem, top_time and top_io). To
2048 * avoid having almost-same code four times, we have this special
2050 if (strncmp(s, "top", 3) == EQUAL) {
2051 if (!parse_top_args(s, arg, obj)) {
2054 } else OBJ(addr, INFO_NET)
2056 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2058 // default to DEFAULTNETDEV
2059 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2060 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2063 #if defined(__linux__)
2064 END OBJ(addrs, INFO_NET)
2066 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2068 // default to DEFAULTNETDEV
2069 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2070 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2073 #endif /* __linux__ */
2075 if (init_tail_object(obj, arg)) {
2076 obj->type = OBJ_text;
2077 obj->data.s = strndup("${tail}", text_buffer_size);
2080 if (init_head_object(obj, arg)) {
2081 obj->type = OBJ_text;
2082 obj->data.s = strndup("${head}", text_buffer_size);
2086 obj->data.s = strndup(arg, text_buffer_size);
2088 CRIT_ERR(obj, free_at_crash, "lines needs a argument");
2092 obj->data.s = strndup(arg, text_buffer_size);
2094 CRIT_ERR(obj, free_at_crash, "words needs a argument");
2096 END OBJ(loadavg, INFO_LOADAVG)
2097 int a = 1, b = 2, c = 3, r = 3;
2100 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2101 if (r >= 3 && (c < 1 || c > 3)) {
2104 if (r >= 2 && (b < 1 || b > 3)) {
2107 if (r >= 1 && (a < 1 || a > 3)) {
2111 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2112 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2113 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2114 END OBJ_IF(if_empty, 0)
2116 ERR("if_empty needs an argument");
2117 obj->data.ifblock.s = 0;
2119 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2120 obj->sub = malloc(sizeof(struct text_object));
2121 extract_variable_text_internal(obj->sub,
2122 obj->data.ifblock.s);
2124 END OBJ_IF(if_match, 0)
2126 ERR("if_match needs arguments");
2127 obj->data.ifblock.s = 0;
2129 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2130 obj->sub = malloc(sizeof(struct text_object));
2131 extract_variable_text_internal(obj->sub,
2132 obj->data.ifblock.s);
2134 END OBJ_IF(if_existing, 0)
2136 ERR("if_existing needs an argument or two");
2137 obj->data.ifblock.s = NULL;
2138 obj->data.ifblock.str = NULL;
2140 char buf1[256], buf2[256];
2141 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2144 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2145 obj->data.ifblock.str = NULL;
2147 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2148 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2151 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2152 END OBJ_IF(if_mounted, 0)
2154 ERR("if_mounted needs an argument");
2155 obj->data.ifblock.s = 0;
2157 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2160 END OBJ_IF(if_running, INFO_TOP)
2162 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2164 END OBJ_IF(if_running, 0)
2168 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2169 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2172 ERR("if_running needs an argument");
2173 obj->data.ifblock.s = 0;
2179 char box[256], dst[256];
2183 /* Kapil: Changed from MAIL_FILE to
2184 current_mail_spool since the latter
2185 is a copy of the former if undefined
2186 but the latter should take precedence
2188 strncpy(box, current_mail_spool, sizeof(box));
2190 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2192 strncpy(box, arg, sizeof(box));
2196 variable_substitute(box, dst, sizeof(dst));
2197 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2198 obj->data.local_mail.interval = n1;
2199 END OBJ(new_mails, 0)
2201 char box[256], dst[256];
2205 strncpy(box, current_mail_spool, sizeof(box));
2207 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2209 strncpy(box, arg, sizeof(box));
2213 variable_substitute(box, dst, sizeof(dst));
2214 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2215 obj->data.local_mail.interval = n1;
2216 END OBJ(seen_mails, 0)
2218 char box[256], dst[256];
2222 strncpy(box, current_mail_spool, sizeof(box));
2224 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2226 strncpy(box, arg, sizeof(box));
2230 variable_substitute(box, dst, sizeof(dst));
2231 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2232 obj->data.local_mail.interval = n1;
2233 END OBJ(unseen_mails, 0)
2235 char box[256], dst[256];
2239 strncpy(box, current_mail_spool, sizeof(box));
2241 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2243 strncpy(box, arg, sizeof(box));
2247 variable_substitute(box, dst, sizeof(dst));
2248 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2249 obj->data.local_mail.interval = n1;
2250 END OBJ(flagged_mails, 0)
2252 char box[256], dst[256];
2256 strncpy(box, current_mail_spool, sizeof(box));
2258 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2260 strncpy(box, arg, sizeof(box));
2264 variable_substitute(box, dst, sizeof(dst));
2265 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2266 obj->data.local_mail.interval = n1;
2267 END OBJ(unflagged_mails, 0)
2269 char box[256], dst[256];
2273 strncpy(box, current_mail_spool, sizeof(box));
2275 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2277 strncpy(box, arg, sizeof(box));
2281 variable_substitute(box, dst, sizeof(dst));
2282 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2283 obj->data.local_mail.interval = n1;
2284 END OBJ(forwarded_mails, 0)
2286 char box[256], dst[256];
2290 strncpy(box, current_mail_spool, sizeof(box));
2292 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2294 strncpy(box, arg, sizeof(box));
2298 variable_substitute(box, dst, sizeof(dst));
2299 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2300 obj->data.local_mail.interval = n1;
2301 END OBJ(unforwarded_mails, 0)
2303 char box[256], dst[256];
2307 strncpy(box, current_mail_spool, sizeof(box));
2309 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2311 strncpy(box, arg, sizeof(box));
2315 variable_substitute(box, dst, sizeof(dst));
2316 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2317 obj->data.local_mail.interval = n1;
2318 END OBJ(replied_mails, 0)
2320 char box[256], dst[256];
2324 strncpy(box, current_mail_spool, sizeof(box));
2326 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2328 strncpy(box, arg, sizeof(box));
2332 variable_substitute(box, dst, sizeof(dst));
2333 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2334 obj->data.local_mail.interval = n1;
2335 END OBJ(unreplied_mails, 0)
2337 char box[256], dst[256];
2341 strncpy(box, current_mail_spool, sizeof(box));
2343 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2345 strncpy(box, arg, sizeof(box));
2349 variable_substitute(box, dst, sizeof(dst));
2350 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2351 obj->data.local_mail.interval = n1;
2352 END OBJ(draft_mails, 0)
2354 char box[256], dst[256];
2358 strncpy(box, current_mail_spool, sizeof(box));
2360 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2362 strncpy(box, arg, sizeof(box));
2366 variable_substitute(box, dst, sizeof(dst));
2367 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2368 obj->data.local_mail.interval = n1;
2369 END OBJ(trashed_mails, 0)
2371 char box[256], dst[256];
2375 strncpy(box, current_mail_spool, sizeof(box));
2377 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2379 strncpy(box, arg, sizeof(box));
2383 variable_substitute(box, dst, sizeof(dst));
2384 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2385 obj->data.local_mail.interval = n1;
2386 END OBJ(mboxscan, 0)
2387 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2388 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2389 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2390 obj->data.mboxscan.output[0] = 1;
2391 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2392 END OBJ(mem, INFO_MEM)
2393 END OBJ(memeasyfree, INFO_MEM)
2394 END OBJ(memfree, INFO_MEM)
2395 END OBJ(memmax, INFO_MEM)
2396 END OBJ(memperc, INFO_MEM)
2398 END OBJ(memgauge, INFO_MEM)
2399 SIZE_DEFAULTS(gauge);
2400 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2402 END OBJ(membar, INFO_MEM)
2404 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2406 END OBJ(memgraph, INFO_MEM)
2408 SIZE_DEFAULTS(graph);
2409 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2410 &obj->e, &obj->char_a, &obj->char_b);
2414 END OBJ(mixer, INFO_MIXER)
2415 obj->data.l = mixer_init(arg);
2416 END OBJ(mixerl, INFO_MIXER)
2417 obj->data.l = mixer_init(arg);
2418 END OBJ(mixerr, INFO_MIXER)
2419 obj->data.l = mixer_init(arg);
2421 END OBJ(mixerbar, INFO_MIXER)
2423 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2424 &obj->data.mixerbar.h);
2425 END OBJ(mixerlbar, INFO_MIXER)
2427 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2428 &obj->data.mixerbar.h);
2429 END OBJ(mixerrbar, INFO_MIXER)
2431 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2432 &obj->data.mixerbar.h);
2434 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2435 obj->data.ifblock.i = mixer_init(arg);
2437 END OBJ(monitor, INFO_X11)
2438 END OBJ(monitor_number, INFO_X11)
2439 END OBJ(desktop, INFO_X11)
2440 END OBJ(desktop_number, INFO_X11)
2441 END OBJ(desktop_name, INFO_X11)
2443 END OBJ(nodename, 0)
2444 END OBJ(processes, INFO_PROCS)
2445 END OBJ(running_processes, INFO_RUN_PROCS)
2446 END OBJ(shadecolor, 0)
2448 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2450 END OBJ(outlinecolor, 0)
2452 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2454 END OBJ(stippled_hr, 0)
2456 int a = stippled_borders, b = 1;
2459 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2460 sscanf(arg, "%d", &b);
2466 obj->data.pair.a = a;
2467 obj->data.pair.b = b;
2469 END OBJ(swap, INFO_MEM)
2470 END OBJ(swapfree, INFO_MEM)
2471 END OBJ(swapmax, INFO_MEM)
2472 END OBJ(swapperc, INFO_MEM)
2473 END OBJ(swapbar, INFO_MEM)
2475 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2478 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2480 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2482 char buf1[256], buf2[256], *fmt, *tz;
2486 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2496 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2497 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2499 END OBJ(iconv_start, 0)
2500 if (iconv_converting) {
2501 CRIT_ERR(obj, free_at_crash, "You must stop your last iconv conversion before "
2502 "starting another");
2505 char iconv_from[CODEPAGE_LENGTH];
2506 char iconv_to[CODEPAGE_LENGTH];
2508 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2509 CRIT_ERR(obj, free_at_crash, "Invalid arguments for iconv_start");
2513 new_iconv = iconv_open(iconv_to, iconv_from);
2514 if (new_iconv == (iconv_t) (-1)) {
2515 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2517 obj->a = register_iconv(&new_iconv);
2518 iconv_converting = 1;
2522 CRIT_ERR(obj, free_at_crash, "Iconv requires arguments");
2524 END OBJ(iconv_stop, 0)
2525 iconv_converting = 0;
2528 END OBJ(totaldown, INFO_NET)
2530 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2532 // default to DEFAULTNETDEV
2533 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2534 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2537 END OBJ(totalup, INFO_NET)
2538 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2540 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2542 // default to DEFAULTNETDEV
2543 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2544 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2548 END OBJ_IF(if_updatenr, 0)
2549 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2550 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
2551 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2553 obj->data.i = arg ? atoi(arg) : 0;
2555 obj->data.i = arg ? atoi(arg) : 0;
2556 END OBJ(upspeed, INFO_NET)
2558 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2560 // default to DEFAULTNETDEV
2561 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2562 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2565 END OBJ(upspeedf, INFO_NET)
2567 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2569 // default to DEFAULTNETDEV
2570 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2571 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2576 END OBJ(upspeedgraph, INFO_NET)
2578 SIZE_DEFAULTS(graph);
2579 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2580 &obj->e, &obj->char_a, &obj->char_b);
2582 // default to DEFAULTNETDEV
2583 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
2584 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2587 END OBJ(uptime_short, INFO_UPTIME)
2588 END OBJ(uptime, INFO_UPTIME)
2589 END OBJ(user_names, INFO_USERS)
2590 END OBJ(user_times, INFO_USERS)
2591 END OBJ(user_terms, INFO_USERS)
2592 END OBJ(user_number, INFO_USERS)
2593 #if defined(__linux__)
2594 END OBJ(gw_iface, INFO_GW)
2595 END OBJ(gw_ip, INFO_GW)
2596 #endif /* !__linux__ */
2598 END OBJ(adt746xcpu, 0)
2599 END OBJ(adt746xfan, 0)
2600 #endif /* !__OpenBSD__ */
2601 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2602 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2603 END OBJ(apm_adapter, 0)
2604 END OBJ(apm_battery_life, 0)
2605 END OBJ(apm_battery_time, 0)
2606 #endif /* __FreeBSD__ */
2607 END OBJ(imap_unseen, 0)
2610 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2615 END OBJ(imap_messages, 0)
2618 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2623 END OBJ(pop3_unseen, 0)
2626 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2631 END OBJ(pop3_used, 0)
2634 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2642 obj->data.s = strndup(arg, text_buffer_size);
2644 ERR("smapi needs an argument");
2645 END OBJ_IF(if_smapi_bat_installed, 0)
2647 ERR("if_smapi_bat_installed needs an argument");
2648 obj->data.ifblock.s = 0;
2650 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2651 END OBJ(smapi_bat_perc, 0)
2653 obj->data.s = strndup(arg, text_buffer_size);
2655 ERR("smapi_bat_perc needs an argument");
2656 END OBJ(smapi_bat_temp, 0)
2658 obj->data.s = strndup(arg, text_buffer_size);
2660 ERR("smapi_bat_temp needs an argument");
2661 END OBJ(smapi_bat_power, 0)
2663 obj->data.s = strndup(arg, text_buffer_size);
2665 ERR("smapi_bat_power needs an argument");
2667 END OBJ(smapi_bat_bar, 0)
2671 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2672 ERR("first argument to smapi_bat_bar must be an integer value");
2676 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2679 ERR("smapi_bat_bar needs an argument");
2683 #define mpd_set_maxlen(name) \
2686 sscanf(arg, "%d", &i); \
2688 obj->data.i = i + 1; \
2690 ERR(#name ": invalid length argument"); \
2692 END OBJ(mpd_artist, INFO_MPD)
2693 mpd_set_maxlen(mpd_artist);
2695 END OBJ(mpd_title, INFO_MPD)
2696 mpd_set_maxlen(mpd_title);
2698 END OBJ(mpd_random, INFO_MPD) init_mpd();
2699 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2700 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2701 END OBJ(mpd_length, INFO_MPD) init_mpd();
2702 END OBJ(mpd_track, INFO_MPD)
2703 mpd_set_maxlen(mpd_track);
2705 END OBJ(mpd_name, INFO_MPD)
2706 mpd_set_maxlen(mpd_name);
2708 END OBJ(mpd_file, INFO_MPD)
2709 mpd_set_maxlen(mpd_file);
2711 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2712 END OBJ(mpd_album, INFO_MPD)
2713 mpd_set_maxlen(mpd_album);
2715 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2716 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2717 END OBJ(mpd_status, INFO_MPD) init_mpd();
2718 END OBJ(mpd_bar, INFO_MPD)
2720 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2722 END OBJ(mpd_smart, INFO_MPD)
2723 mpd_set_maxlen(mpd_smart);
2725 END OBJ_IF(if_mpd_playing, INFO_MPD)
2727 #undef mpd_set_maxlen
2730 END OBJ(moc_state, INFO_MOC)
2731 END OBJ(moc_file, INFO_MOC)
2732 END OBJ(moc_title, INFO_MOC)
2733 END OBJ(moc_artist, INFO_MOC)
2734 END OBJ(moc_song, INFO_MOC)
2735 END OBJ(moc_album, INFO_MOC)
2736 END OBJ(moc_totaltime, INFO_MOC)
2737 END OBJ(moc_timeleft, INFO_MOC)
2738 END OBJ(moc_curtime, INFO_MOC)
2739 END OBJ(moc_bitrate, INFO_MOC)
2740 END OBJ(moc_rate, INFO_MOC)
2743 END OBJ(xmms2_artist, INFO_XMMS2)
2744 END OBJ(xmms2_album, INFO_XMMS2)
2745 END OBJ(xmms2_title, INFO_XMMS2)
2746 END OBJ(xmms2_genre, INFO_XMMS2)
2747 END OBJ(xmms2_comment, INFO_XMMS2)
2748 END OBJ(xmms2_url, INFO_XMMS2)
2749 END OBJ(xmms2_tracknr, INFO_XMMS2)
2750 END OBJ(xmms2_bitrate, INFO_XMMS2)
2751 END OBJ(xmms2_date, INFO_XMMS2)
2752 END OBJ(xmms2_id, INFO_XMMS2)
2753 END OBJ(xmms2_duration, INFO_XMMS2)
2754 END OBJ(xmms2_elapsed, INFO_XMMS2)
2755 END OBJ(xmms2_size, INFO_XMMS2)
2756 END OBJ(xmms2_status, INFO_XMMS2)
2757 END OBJ(xmms2_percent, INFO_XMMS2)
2759 END OBJ(xmms2_bar, INFO_XMMS2)
2761 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2763 END OBJ(xmms2_smart, INFO_XMMS2)
2764 END OBJ(xmms2_playlist, INFO_XMMS2)
2765 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2766 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2769 END OBJ(audacious_status, INFO_AUDACIOUS)
2770 END OBJ(audacious_title, INFO_AUDACIOUS)
2772 sscanf(arg, "%d", &info.audacious.max_title_len);
2773 if (info.audacious.max_title_len > 0) {
2774 info.audacious.max_title_len++;
2776 CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
2779 END OBJ(audacious_length, INFO_AUDACIOUS)
2780 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2781 END OBJ(audacious_position, INFO_AUDACIOUS)
2782 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2783 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2784 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2785 END OBJ(audacious_channels, INFO_AUDACIOUS)
2786 END OBJ(audacious_filename, INFO_AUDACIOUS)
2787 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2788 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2789 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2791 END OBJ(audacious_bar, INFO_AUDACIOUS)
2793 scan_bar(arg, &obj->a, &obj->b);
2797 END OBJ(bmpx_title, INFO_BMPX)
2798 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2799 END OBJ(bmpx_artist, INFO_BMPX)
2800 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2801 END OBJ(bmpx_album, INFO_BMPX)
2802 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2803 END OBJ(bmpx_track, INFO_BMPX)
2804 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2805 END OBJ(bmpx_uri, INFO_BMPX)
2806 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2807 END OBJ(bmpx_bitrate, INFO_BMPX)
2808 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2814 char *userid = (char *) malloc(20 * sizeof(char));
2815 char *apikey = (char *) malloc(64 * sizeof(char));
2816 char *charid = (char *) malloc(20 * sizeof(char));
2818 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2819 obj->data.eve.charid = charid;
2820 obj->data.eve.userid = userid;
2821 obj->data.eve.apikey = apikey;
2825 CRIT_ERR(obj, free_at_crash, "eve needs arguments: <userid> <apikey> <characterid>");
2833 char *uri = (char *) malloc(128 * sizeof(char));
2835 argc = sscanf(arg, "%127s %f", uri, &interval);
2837 obj->data.curl.uri = uri;
2838 obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
2840 ERR("wrong number of arguments for $curl");
2843 CRIT_ERR(obj, free_at_crash, "curl needs arguments: <uri> <interval in minutes>");
2851 unsigned int nrspaces = 0;
2852 char *uri = (char *) malloc(128 * sizeof(char));
2853 char *action = (char *) malloc(64 * sizeof(char));
2855 argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
2856 &act_par, &nrspaces);
2858 obj->data.rss.uri = uri;
2859 obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
2860 obj->data.rss.action = action;
2861 obj->data.rss.act_par = act_par;
2862 obj->data.rss.nrspaces = nrspaces;
2864 ERR("wrong number of arguments for $rss");
2867 CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
2868 "[act_par] [spaces in front]");
2876 char *locID = (char *) malloc(9 * sizeof(char));
2877 char *uri = (char *) malloc(128 * sizeof(char));
2878 char *data_type = (char *) malloc(32 * sizeof(char));
2881 argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
2884 /* locID MUST BE upper-case */
2887 *tmp_p = toupper(*tmp_p);
2891 /* Construct complete uri */
2892 if (strstr(uri, "xoap.weather.com")) {
2900 } else if (strstr(uri, "weather.noaa.gov")) {
2902 strcat(uri, ".TXT");
2903 } else if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
2904 CRIT_ERR(obj, free_at_crash, \
2905 "could not recognize the weather uri");
2908 obj->data.weather.uri = uri;
2909 obj->data.weather.data_type = data_type;
2911 /* Limit the data retrieval interval to half hour min */
2912 if (interval < 30) {
2916 /* Convert to seconds */
2917 obj->data.weather.interval = interval * 60;
2920 DBGP("weather: fetching %s from %s every %d seconds", \
2921 data_type, uri, obj->data.weather.interval);
2923 ERR("wrong number of arguments for $weather");
2926 CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
2932 obj->data.s = strndup(arg, text_buffer_size);
2934 CRIT_ERR(obj, free_at_crash, "lua needs arguments: <function name> [function parameters]");
2936 END OBJ(lua_parse, 0)
2938 obj->data.s = strndup(arg, text_buffer_size);
2940 CRIT_ERR(obj, free_at_crash, "lua_parse needs arguments: <function name> [function parameters]");
2945 arg = scan_bar(arg, &obj->a, &obj->b);
2947 obj->data.s = strndup(arg, text_buffer_size);
2949 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2952 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2955 END OBJ(lua_graph, 0)
2956 SIZE_DEFAULTS(graph);
2959 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2960 &obj->e, &obj->char_a, &obj->char_b);
2964 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
2967 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
2969 END OBJ(lua_gauge, 0)
2970 SIZE_DEFAULTS(gauge);
2972 arg = scan_gauge(arg, &obj->a, &obj->b);
2974 obj->data.s = strndup(arg, text_buffer_size);
2976 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2979 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2982 #endif /* HAVE_LUA */
2985 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2986 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2987 ERR("hddtemp needs arguments");
2988 obj->type = OBJ_text;
2989 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2990 obj->data.hddtemp.update_time = 0;
2992 obj->data.hddtemp.temp = NULL;
2993 #endif /* HDDTEMP */
2994 #ifdef TCP_PORT_MONITOR
2995 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2996 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2997 #endif /* TCP_PORT_MONITOR */
2998 END OBJ(entropy_avail, INFO_ENTROPY)
2999 END OBJ(entropy_perc, INFO_ENTROPY)
3000 END OBJ(entropy_poolsize, INFO_ENTROPY)
3001 END OBJ(entropy_bar, INFO_ENTROPY)
3003 scan_bar(arg, &obj->a, &obj->b);
3006 obj->sub = malloc(sizeof(struct text_object));
3007 extract_variable_text_internal(obj->sub, arg);
3009 CRIT_ERR(obj, free_at_crash, "blink needs a argument");
3011 END OBJ(to_bytes, 0)
3013 obj->sub = malloc(sizeof(struct text_object));
3014 extract_variable_text_internal(obj->sub, arg);
3016 CRIT_ERR(obj, free_at_crash, "to_bytes needs a argument");
3021 obj->data.scroll.resetcolor = current_text_color;
3022 obj->data.scroll.step = 1;
3023 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
3024 sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2);
3025 if (*(arg + n1 + n2)) {
3028 obj->data.scroll.step = 1;
3030 obj->data.scroll.text = malloc(strlen(arg + n1) + obj->data.scroll.show + 1);
3031 for(n2 = 0; (unsigned int) n2 < obj->data.scroll.show; n2++) {
3032 obj->data.scroll.text[n2] = ' ';
3034 obj->data.scroll.text[n2] = 0;
3035 strcat(obj->data.scroll.text, arg + n1);
3036 obj->data.scroll.start = 0;
3037 obj->sub = malloc(sizeof(struct text_object));
3038 extract_variable_text_internal(obj->sub,
3039 obj->data.scroll.text);
3041 CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
3046 unsigned int indenting = 0; //vars can be used as args for other vars
3049 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
3051 for (i=0; arg[i] != 0 && j < 2; i++) {
3052 if(startvar[j] == -1) {
3056 }else if(endvar[j] == -1) {
3059 }else if(arg[i] == '}') {
3062 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
3068 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
3069 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
3070 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
3071 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
3073 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
3074 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
3076 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
3077 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
3079 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
3080 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
3082 obj->sub = malloc(sizeof(struct text_object));
3083 extract_variable_text_internal(obj->sub, obj->data.combine.left);
3084 obj->sub->sub = malloc(sizeof(struct text_object));
3085 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
3087 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
3090 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
3095 CRIT_ERR(obj, free_at_crash, "nvidia needs an argument\n");
3096 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
3097 CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
3098 " specified: '%s'\n", arg);
3103 END OBJ(apcupsd, INFO_APCUPSD)
3107 if (sscanf(arg, "%63s %d", host, &port) != 2) {
3108 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
3110 info.apcupsd.port = htons(port);
3111 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
3114 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
3116 END OBJ(apcupsd_name, INFO_APCUPSD)
3117 END OBJ(apcupsd_model, INFO_APCUPSD)
3118 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
3119 END OBJ(apcupsd_cable, INFO_APCUPSD)
3120 END OBJ(apcupsd_status, INFO_APCUPSD)
3121 END OBJ(apcupsd_linev, INFO_APCUPSD)
3122 END OBJ(apcupsd_load, INFO_APCUPSD)
3123 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
3125 scan_bar(arg, &obj->a, &obj->b);
3127 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
3129 SIZE_DEFAULTS(graph);
3130 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3131 &obj->e, &obj->char_a, &obj->char_b);
3133 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
3134 SIZE_DEFAULTS(gauge);
3135 scan_gauge(arg, &obj->a, &obj->b);
3137 END OBJ(apcupsd_charge, INFO_APCUPSD)
3138 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
3139 END OBJ(apcupsd_temp, INFO_APCUPSD)
3140 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
3141 #endif /* APCUPSD */
3145 ERR("unknown variable %s", s);
3146 obj->type = OBJ_text;
3147 snprintf(buf, 256, "${%s}", s);
3148 obj->data.s = strndup(buf, text_buffer_size);
3155 static struct text_object *create_plain_text(const char *s)
3157 struct text_object *obj;
3159 if (s == NULL || *s == '\0') {
3163 obj = new_text_object_internal();
3165 obj->type = OBJ_text;
3166 obj->data.s = strndup(s, text_buffer_size);
3170 /* backslash_escape - do the actual substitution task for template objects
3172 * The field templates is used for substituting the \N occurences. Set it to
3173 * NULL to leave them as they are.
3175 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
3179 unsigned int dup_idx = 0, dup_len;
3181 dup_len = strlen(src) + 1;
3182 src_dup = malloc(dup_len * sizeof(char));
3190 if (*(p + 1) == '\\') {
3191 src_dup[dup_idx++] = '\\';
3193 } else if (*(p + 1) == ' ') {
3194 src_dup[dup_idx++] = ' ';
3196 } else if (*(p + 1) == 'n') {
3197 src_dup[dup_idx++] = '\n';
3199 } else if (templates) {
3200 unsigned int tmpl_num;
3202 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
3203 (tmpl_num > template_count))
3205 dup_len += strlen(templates[tmpl_num - 1]);
3206 src_dup = realloc(src_dup, dup_len * sizeof(char));
3207 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
3208 dup_idx += strlen(templates[tmpl_num - 1]);
3213 src_dup[dup_idx++] = *p;
3218 src_dup[dup_idx] = '\0';
3219 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
3223 /* handle_template_object - core logic of the template object
3225 * use config variables like this:
3226 * template1 = "$\1\2"
3227 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
3229 * and use them like this:
3230 * ${template1 node name}
3231 * ${template2 root /}
3232 * ${template2 cdrom /mnt/cdrom}
3234 static char *handle_template(const char *tmpl, const char *args)
3236 char *args_dup = NULL;
3238 char **argsp = NULL;
3239 unsigned int argcnt = 0, template_idx, i;
3242 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
3243 (template_idx >= MAX_TEMPLATES))
3247 args_dup = strdup(args);
3250 while (*p && (*p == ' ' && (p == args_dup || *(p - 1) != '\\')))
3252 if (p > args_dup && *(p - 1) == '\\')
3255 while (*p && (*p != ' ' || (p > args_dup && *(p - 1) == '\\')))
3261 argsp = realloc(argsp, ++argcnt * sizeof(char *));
3262 argsp[argcnt - 1] = p_old;
3264 for (i = 0; i < argcnt; i++) {
3266 tmp = backslash_escape(argsp[i], NULL, 0);
3267 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
3272 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
3273 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
3275 for (i = 0; i < argcnt; i++)
3281 static char *find_and_replace_templates(const char *inbuf)
3283 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3286 outlen = strlen(inbuf) + 1;
3287 o = outbuf = calloc(outlen, sizeof(char));
3288 memset(outbuf, 0, outlen * sizeof(char));
3290 p = indup = strdup(inbuf);
3292 while (*p && *p != '$')
3298 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3303 if (*(p + 1) == '{') {
3306 while (*p && !isspace(*p) && *p != '{' && *p != '}')
3314 while (*p && stack > 0) {
3322 // stack is empty. that means the previous char was }, so we zero it
3325 // we ran into the end of string without finding a closing }, bark
3326 CRIT_ERR(NULL, NULL, "cannot find a closing '}' in template expansion");
3330 while (*p && !isspace(*p))
3334 tmpl_out = handle_template(templ, args);
3336 outlen += strlen(tmpl_out);
3338 outbuf = realloc(outbuf, outlen * sizeof(char));
3339 strcat (outbuf, tmpl_out);
3341 o = outbuf + strlen(outbuf);
3343 ERR("failed to handle template '%s' with args '%s'", templ, args);
3347 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3352 static int text_contains_templates(const char *text)
3354 if (strcasestr(text, "${template") != NULL)
3356 if (strcasestr(text, "$template") != NULL)
3361 /* folds a string over top of itself, like so:
3363 * if start is "blah", and you call it with count = 1, the result will be "lah"
3365 static void strfold(char *start, int count)
3368 for (curplace = start + count; *curplace != 0; curplace++) {
3369 *(curplace - count) = *curplace;
3371 *(curplace - count) = 0;
3375 * - assumes that *string is '#'
3376 * - removes the part from '#' to the end of line ('\n' or '\0')
3377 * - it removes the '\n'
3378 * - copies the last char into 'char *last' argument, which should be a pointer
3379 * to a char rather than a string.
3381 static size_t remove_comment(char *string, char *last)
3384 while (*end != '\0' && *end != '\n') {
3387 if (last) *last = *end;
3388 if (*end == '\n') end++;
3389 strfold(string, end - string);
3390 return end - string;
3393 static size_t remove_comments(char *string)
3397 for (curplace = string; *curplace != 0; curplace++) {
3398 if (*curplace == '\\' && *(curplace + 1) == '#') {
3399 // strcpy can't be used for overlapping strings
3400 strfold(curplace, 1);
3402 } else if (*curplace == '#') {
3403 folded += remove_comment(curplace, 0);
3409 static int extract_variable_text_internal(struct text_object *retval, const char *const_p)
3411 struct text_object *obj;
3412 char *p, *s, *orig_p;
3414 void *ifblock_opaque = NULL;
3419 p = strndup(const_p, max_user_text - 1);
3420 while (text_contains_templates(p)) {
3422 tmp = find_and_replace_templates(p);
3428 if (strcmp(p, const_p)) {
3429 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3431 DBGP("no templates to replace");
3434 memset(retval, 0, sizeof(struct text_object));
3436 line = global_text_lines;
3444 obj = create_plain_text(s);
3446 append_object(retval, obj);
3456 /* variable is either $foo or ${foo} */
3458 unsigned int brl = 1, brr = 0;
3462 while (*p && brl != brr) {
3477 while (*p && (isalnum((int) *p) || *p == '_')) {
3482 /* copy variable to buffer */
3483 len = (p - s > 255) ? 255 : (p - s);
3484 strncpy(buf, s, len);
3492 /* search for variable in environment */
3496 obj = create_plain_text(var);
3498 append_object(retval, obj);
3503 /* if variable wasn't found in environment, use some special */
3508 if (strchr(buf, ' ')) {
3509 arg = strchr(buf, ' ');
3512 while (isspace((int) *arg)) {
3520 /* lowercase variable name */
3523 *tmp_p = tolower(*tmp_p);
3527 obj = construct_text_object(buf, arg,
3528 line, &ifblock_opaque, orig_p);
3530 append_object(retval, obj);
3534 obj = create_plain_text("$");
3537 append_object(retval, obj);
3540 } else if (*p == '\\' && *(p+1) == '#') {
3542 } else if (*p == '#') {
3544 if (remove_comment(p, &c) && p > orig_p && c == '\n') {
3545 /* if remove_comment removed a newline, we need to 'back up' with p */
3551 obj = create_plain_text(s);
3553 append_object(retval, obj);
3556 if (!ifblock_stack_empty(&ifblock_opaque)) {
3557 ERR("one or more $endif's are missing");
3564 static void extract_variable_text(const char *p)
3566 free_text_objects(&global_root_object, 0);
3580 extract_variable_text_internal(&global_root_object, p);
3583 void parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3585 extract_variable_text_internal(root, txt);
3586 generate_text_internal(p, max_user_text, *root, cur);
3590 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3591 void *thread(void *), const char *text)
3593 if (obj->char_b && info.mail) {
3594 // this means we use info
3595 if (!info.mail->p_timed_thread) {
3596 info.mail->p_timed_thread =
3597 timed_thread_create(thread,
3598 (void *) info.mail, info.mail->interval * 1000000);
3599 if (!info.mail->p_timed_thread) {
3600 ERR("Error creating %s timed thread", text);
3602 timed_thread_register(info.mail->p_timed_thread,
3603 &info.mail->p_timed_thread);
3604 if (timed_thread_run(info.mail->p_timed_thread)) {
3605 ERR("Error running %s timed thread", text);
3609 } else if (obj->data.mail) {
3610 // this means we use obj
3611 if (!obj->data.mail->p_timed_thread) {
3612 obj->data.mail->p_timed_thread =
3613 timed_thread_create(thread,
3614 (void *) obj->data.mail,
3615 obj->data.mail->interval * 1000000);
3616 if (!obj->data.mail->p_timed_thread) {
3617 ERR("Error creating %s timed thread", text);
3619 timed_thread_register(obj->data.mail->p_timed_thread,
3620 &obj->data.mail->p_timed_thread);
3621 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3622 ERR("Error running %s timed thread", text);
3625 return obj->data.mail;
3626 } else if (!obj->a) {
3627 // something is wrong, warn once then stop
3628 ERR("There's a problem with your mail settings. "
3629 "Check that the global mail settings are properly defined"
3630 " (line %li).", obj->line);
3636 char *format_time(unsigned long timeval, const int width)
3639 unsigned long nt; // narrow time, for speed on 32-bit
3640 unsigned cc; // centiseconds
3641 unsigned nn; // multi-purpose whatever
3644 cc = nt % 100; // centiseconds past second
3645 nt /= 100; // total seconds
3646 nn = nt % 60; // seconds past the minute
3647 nt /= 60; // total minutes
3648 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3650 return strndup(buf, text_buffer_size);
3652 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3653 return strndup(buf, text_buffer_size);
3655 nn = nt % 60; // minutes past the hour
3656 nt /= 60; // total hours
3657 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3658 return strndup(buf, text_buffer_size);
3660 nn = nt; // now also hours
3661 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3662 return strndup(buf, text_buffer_size);
3664 nn /= 24; // now days
3665 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3666 return strndup(buf, text_buffer_size);
3668 nn /= 7; // now weeks
3669 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3670 return strndup(buf, text_buffer_size);
3672 // well shoot, this outta' fit...
3673 return strndup("<inf>", text_buffer_size);
3676 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3677 //string has to end with \0 and it's length should fit in a int
3679 void remove_deleted_chars(char *string){
3681 while(string[i] != 0){
3682 if(string[i] == BACKSPACE){
3684 strcpy( &(string[i-1]), &(string[i+1]) );
3686 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3691 static inline void format_media_player_time(char *buf, const int size,
3694 int days, hours, minutes;
3696 days = seconds / (24 * 60 * 60);
3697 seconds %= (24 * 60 * 60);
3698 hours = seconds / (60 * 60);
3699 seconds %= (60 * 60);
3700 minutes = seconds / 60;
3704 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3705 hours, minutes, seconds);
3706 } else if (hours > 0) {
3707 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3710 snprintf(buf, size, "%i:%02i", minutes, seconds);
3714 static inline double get_barnum(char *buf)
3726 if (sscanf(buf, "%lf", &barnum) == 0) {
3727 ERR("reading exec value failed (perhaps it's not the "
3728 "correct format?)");
3731 if (barnum > 100.0 || barnum < 0.0) {
3732 ERR("your exec value is not between 0 and 100, "
3733 "therefore it will be ignored");
3739 /* substitutes all occurrences of '\n' with SECRIT_MULTILINE_CHAR, which allows
3740 * multiline objects like $exec work with $align[rc] and friends
3742 void substitute_newlines(char *p, long l)
3746 while (p && *p && p < s + l) {
3748 /* only substitute if it's not the last newline */
3749 *p = SECRIT_MULTILINE_CHAR;
3755 static void generate_text_internal(char *p, int p_max_size,
3756 struct text_object root, struct information *cur)
3758 struct text_object *obj;
3760 int need_to_load_fonts = 0;
3763 /* for the OBJ_top* handler */
3764 struct process **needed = 0;
3767 char buff_in[p_max_size];
3769 iconv_converting = 0;
3770 #endif /* HAVE_ICONV */
3774 while (obj && p_max_size > 0) {
3775 needed = 0; /* reset for top stuff */
3777 /* IFBLOCK jumping algorithm
3779 * This is easier as it looks like:
3780 * - each IF checks it's condition
3781 * - on FALSE: call DO_JUMP
3782 * - on TRUE: don't care
3783 * - each ELSE calls DO_JUMP unconditionally
3784 * - each ENDIF is silently being ignored
3787 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3788 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3789 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3790 * regularly, "obj" is being updated to point to obj->next, so object parsing
3791 * continues right after the corresponding ELSE or ENDIF. This means that if we
3792 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3793 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3794 * jumped, and there is nothing to do.
3798 obj = obj->data.ifblock.next; \
3801 #define OBJ(a) break; case OBJ_##a:
3803 switch (obj->type) {
3805 ERR("not implemented obj type %d", obj->type);
3808 struct sockaddr_in addr;
3809 struct hostent* he = gethostbyname(obj->data.read_tcp.host);
3811 sock = socket(he->h_addrtype, SOCK_STREAM, 0);
3813 memset(&addr, 0, sizeof(addr));
3814 addr.sin_family = AF_INET;
3815 addr.sin_port = obj->data.read_tcp.port;
3816 memcpy(&addr.sin_addr, he->h_addr, he->h_length);
3817 if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) == 0) {
3821 FD_SET(sock, &readfds);
3824 if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){
3825 received = recv(sock, p, p_max_size, 0);
3830 ERR("read_tcp: Couldn't create a connection");
3833 ERR("read_tcp: Couldn't create a socket");
3836 ERR("read_tcp: Problem with resolving the hostname");
3841 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3843 #endif /* !__OpenBSD__ */
3846 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3847 obj->data.cpu_index);
3853 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3854 obj->data.cpu_index);
3856 /* OpenBSD has no such flag (SUSv2) */
3857 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3858 obj->data.cpu_index);
3859 #endif /* __OpenBSD */
3862 #if defined(__linux__)
3865 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3866 obj->data.cpu_index);
3871 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3872 obj->data.cpu_index);
3877 OBJ(wireless_essid) {
3878 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3880 OBJ(wireless_mode) {
3881 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3883 OBJ(wireless_bitrate) {
3884 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3887 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3889 OBJ(wireless_link_qual) {
3890 spaced_print(p, p_max_size, "%d", 4,
3891 obj->data.net->link_qual);
3893 OBJ(wireless_link_qual_max) {
3894 spaced_print(p, p_max_size, "%d", 4,
3895 obj->data.net->link_qual_max);
3897 OBJ(wireless_link_qual_perc) {
3898 if (obj->data.net->link_qual_max > 0) {
3899 spaced_print(p, p_max_size, "%.0f", 5,
3900 (double) obj->data.net->link_qual /
3901 obj->data.net->link_qual_max * 100);
3903 spaced_print(p, p_max_size, "unk", 5);
3906 OBJ(wireless_link_bar) {
3908 if(output_methods & TO_X) {
3909 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3910 obj->data.net->link_qual_max) * 255.0);
3913 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3914 new_bar_in_shell(p, p_max_size, ((double) obj->data.net->link_qual /
3915 obj->data.net->link_qual_max) * 100.0, obj->a);
3920 #endif /* HAVE_IWLIB */
3922 #endif /* __linux__ */
3926 get_adt746x_cpu(p, p_max_size);
3929 get_adt746x_fan(p, p_max_size);
3932 get_acpi_fan(p, p_max_size);
3934 OBJ(acpiacadapter) {
3935 get_acpi_ac_adapter(p, p_max_size);
3938 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3941 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3943 OBJ(battery_percent) {
3944 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3948 if(output_methods & TO_X) {
3949 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3952 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3953 new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
3958 OBJ(battery_short) {
3959 get_battery_short_status(p, p_max_size, obj->data.s);
3961 #endif /* __OpenBSD__ */
3964 human_readable(cur->buffers * 1024, p, 255);
3967 human_readable(cur->cached * 1024, p, 255);
3970 if (obj->data.cpu_index > info.cpu_count) {
3971 ERR("obj->data.cpu_index %i info.cpu_count %i",
3972 obj->data.cpu_index, info.cpu_count);
3973 CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
3975 percent_print(p, p_max_size,
3976 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3980 new_gauge(p, obj->a, obj->b,
3981 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3985 if(output_methods & TO_X) {
3986 new_bar(p, obj->a, obj->b,
3987 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3990 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3991 new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a);
3998 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3999 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4000 100, 1, obj->char_a, obj->char_b);
4003 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
4004 obj->e, 1, obj->char_a, obj->char_b);
4007 new_fg(p, obj->data.l);
4040 OBJ(conky_version) {
4041 snprintf(p, p_max_size, "%s", VERSION);
4043 OBJ(conky_build_date) {
4044 snprintf(p, p_max_size, "%s", BUILD_DATE);
4046 OBJ(conky_build_arch) {
4047 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4049 #if defined(__linux__)
4051 snprintf(p, p_max_size, "%s",
4052 get_disk_protect_queue(obj->data.s));
4055 snprintf(p, p_max_size, "%s", i8k.version);
4058 snprintf(p, p_max_size, "%s", i8k.bios);
4061 snprintf(p, p_max_size, "%s", i8k.serial);
4066 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4067 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
4069 OBJ(i8k_left_fan_status) {
4070 int left_fan_status;
4072 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4073 if (left_fan_status == 0) {
4074 snprintf(p, p_max_size, "off");
4076 if (left_fan_status == 1) {
4077 snprintf(p, p_max_size, "low");
4079 if (left_fan_status == 2) {
4080 snprintf(p, p_max_size, "high");
4083 OBJ(i8k_right_fan_status) {
4084 int right_fan_status;
4086 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4087 if (right_fan_status == 0) {
4088 snprintf(p, p_max_size, "off");
4090 if (right_fan_status == 1) {
4091 snprintf(p, p_max_size, "low");
4093 if (right_fan_status == 2) {
4094 snprintf(p, p_max_size, "high");
4097 OBJ(i8k_left_fan_rpm) {
4098 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4100 OBJ(i8k_right_fan_rpm) {
4101 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4103 OBJ(i8k_ac_status) {
4106 sscanf(i8k.ac_status, "%d", &ac_status);
4107 if (ac_status == -1) {
4108 snprintf(p, p_max_size, "disabled (read i8k docs)");
4110 if (ac_status == 0) {
4111 snprintf(p, p_max_size, "off");
4113 if (ac_status == 1) {
4114 snprintf(p, p_max_size, "on");
4117 OBJ(i8k_buttons_status) {
4118 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4122 get_ibm_acpi_fan(p, p_max_size);
4125 get_ibm_acpi_temps();
4126 temp_print(p, p_max_size,
4127 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
4130 get_ibm_acpi_volume(p, p_max_size);
4132 OBJ(ibm_brightness) {
4133 get_ibm_acpi_brightness(p, p_max_size);
4136 /* information from sony_laptop kernel module
4137 * /sys/devices/platform/sony-laptop */
4138 OBJ(sony_fanspeed) {
4139 get_sony_fanspeed(p, p_max_size);
4142 if (!cur->gw_info.count) {
4147 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4150 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4153 snprintf(p, p_max_size, "%d", get_laptop_mode());
4156 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4158 #endif /* __linux__ */
4159 #if (defined(__FreeBSD__) || defined(__linux__))
4161 if ((obj->data.ifblock.s)
4162 && (!interface_up(obj->data.ifblock.s))) {
4168 OBJ(obsd_sensors_temp) {
4169 obsd_sensors.device = sensor_device;
4170 update_obsd_sensors();
4171 temp_print(p, p_max_size,
4172 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
4175 OBJ(obsd_sensors_fan) {
4176 obsd_sensors.device = sensor_device;
4177 update_obsd_sensors();
4178 snprintf(p, p_max_size, "%d",
4179 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4181 OBJ(obsd_sensors_volt) {
4182 obsd_sensors.device = sensor_device;
4183 update_obsd_sensors();
4184 snprintf(p, p_max_size, "%.2f",
4185 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4188 get_obsd_vendor(p, p_max_size);
4191 get_obsd_product(p, p_max_size);
4193 #endif /* __OpenBSD__ */
4196 new_font(p, obj->data.s);
4197 need_to_load_fonts = 1;
4200 /* TODO: move this correction from kB to kB/s elsewhere
4201 * (or get rid of it??) */
4203 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
4207 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
4211 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
4216 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4217 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
4219 OBJ(diskiograph_read) {
4220 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4221 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
4223 OBJ(diskiograph_write) {
4224 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4225 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
4229 human_readable(obj->data.net->recv_speed, p, 255);
4232 spaced_print(p, p_max_size, "%.1f", 8,
4233 obj->data.net->recv_speed / 1024.0);
4236 OBJ(downspeedgraph) {
4237 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4238 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4242 /* Since we see you, you're if has not jumped.
4243 * Do Ninja jump here: without leaving traces.
4244 * This is to prevent us from stale jumped flags.
4246 obj = obj->data.ifblock.next;
4250 /* harmless object, just ignore */
4254 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4255 && (obj->data.net->addr.sa_data[3] & 255) == 0
4256 && (obj->data.net->addr.sa_data[4] & 255) == 0
4257 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4258 snprintf(p, p_max_size, "No Address");
4260 snprintf(p, p_max_size, "%u.%u.%u.%u",
4261 obj->data.net->addr.sa_data[2] & 255,
4262 obj->data.net->addr.sa_data[3] & 255,
4263 obj->data.net->addr.sa_data[4] & 255,
4264 obj->data.net->addr.sa_data[5] & 255);
4267 #if defined(__linux__)
4269 if (NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2) {
4270 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4271 strcpy(p, obj->data.net->addrs);
4273 strcpy(p, "0.0.0.0");
4276 #endif /* __linux__ */
4277 #if defined(IMLIB2) && defined(X11)
4279 /* doesn't actually draw anything, just queues it omp. the
4280 * image will get drawn after the X event loop */
4281 cimlib_add_image(obj->data.s);
4285 evaluate(obj->data.s, p);
4288 read_exec(obj->data.s, p, text_buffer_size);
4289 remove_deleted_chars(p);
4292 struct information *tmp_info;
4293 struct text_object subroot;
4295 read_exec(obj->data.s, p, text_buffer_size);
4297 tmp_info = malloc(sizeof(struct information));
4298 memcpy(tmp_info, cur, sizeof(struct information));
4299 parse_conky_vars(&subroot, p, p, tmp_info);
4301 free_text_objects(&subroot, 1);
4308 read_exec(obj->data.s, p, text_buffer_size);
4309 barnum = get_barnum(p); /*using the same function*/
4311 if (barnum >= 0.0) {
4313 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4320 read_exec(obj->data.s, p, text_buffer_size);
4321 barnum = get_barnum(p);
4323 if (barnum >= 0.0) {
4325 if(output_methods & TO_X) {
4327 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4330 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4331 new_bar_in_shell(p, p_max_size, barnum, obj->a);
4339 char showaslog = FALSE;
4340 char tempgrad = FALSE;
4342 char *cmd = obj->data.s;
4344 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4346 cmd += strlen(" "TEMPGRAD);
4348 if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) {
4350 cmd += strlen(" "LOGGRAPH);
4352 read_exec(cmd, p, text_buffer_size);
4353 barnum = get_barnum(p);
4356 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
4357 100, 1, showaslog, tempgrad);
4362 if (current_update_time - obj->data.execi.last_update
4363 >= obj->data.execi.interval) {
4366 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4367 barnum = get_barnum(p);
4369 if (barnum >= 0.0) {
4372 obj->data.execi.last_update = current_update_time;
4375 if(output_methods & TO_X) {
4376 new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
4379 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4380 new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
4387 if (current_update_time - obj->data.execi.last_update
4388 >= obj->data.execi.interval) {
4390 char showaslog = FALSE;
4391 char tempgrad = FALSE;
4392 char *cmd = obj->data.execi.cmd;
4394 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4396 cmd += strlen(" "TEMPGRAD);
4398 if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) {
4400 cmd += strlen(" "LOGGRAPH);
4402 obj->char_a = showaslog;
4403 obj->char_b = tempgrad;
4404 read_exec(cmd, p, text_buffer_size);
4405 barnum = get_barnum(p);
4407 if (barnum >= 0.0) {
4410 obj->data.execi.last_update = current_update_time;
4412 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4415 if (current_update_time - obj->data.execi.last_update
4416 >= obj->data.execi.interval) {
4419 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4420 barnum = get_barnum(p);
4422 if (barnum >= 0.0) {
4423 obj->f = 255 * barnum / 100.0;
4425 obj->data.execi.last_update = current_update_time;
4427 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4431 if (current_update_time - obj->data.execi.last_update
4432 >= obj->data.execi.interval
4433 && obj->data.execi.interval != 0) {
4434 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4436 obj->data.execi.last_update = current_update_time;
4438 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4441 struct text_object subroot;
4442 struct information *tmp_info =
4443 malloc(sizeof(struct information));
4444 memcpy(tmp_info, cur, sizeof(struct information));
4446 if (current_update_time - obj->data.execi.last_update
4447 < obj->data.execi.interval
4448 || obj->data.execi.interval == 0) {
4449 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4451 char *output = obj->data.execi.buffer;
4452 FILE *fp = popen(obj->data.execi.cmd, "r");
4453 int length = fread(output, 1, text_buffer_size, fp);
4457 output[length] = '\0';
4458 if (length > 0 && output[length - 1] == '\n') {
4459 output[length - 1] = '\0';
4462 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4463 obj->data.execi.last_update = current_update_time;
4465 free_text_objects(&subroot, 1);
4469 if (!obj->data.texeci.p_timed_thread) {
4470 obj->data.texeci.p_timed_thread =
4471 timed_thread_create(&threaded_exec,
4472 (void *) obj, obj->data.texeci.interval * 1000000);
4473 if (!obj->data.texeci.p_timed_thread) {
4474 ERR("Error creating texeci timed thread");
4477 * note that we don't register this thread with the
4478 * timed_thread list, because we destroy it manually
4480 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4481 ERR("Error running texeci timed thread");
4484 timed_thread_lock(obj->data.texeci.p_timed_thread);
4485 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4486 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4489 #endif /* HAVE_POPEN */
4491 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4493 if (mail && mail->p_timed_thread) {
4494 timed_thread_lock(mail->p_timed_thread);
4495 snprintf(p, p_max_size, "%lu", mail->unseen);
4496 timed_thread_unlock(mail->p_timed_thread);
4499 OBJ(imap_messages) {
4500 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4502 if (mail && mail->p_timed_thread) {
4503 timed_thread_lock(mail->p_timed_thread);
4504 snprintf(p, p_max_size, "%lu", mail->messages);
4505 timed_thread_unlock(mail->p_timed_thread);
4509 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4511 if (mail && mail->p_timed_thread) {
4512 timed_thread_lock(mail->p_timed_thread);
4513 snprintf(p, p_max_size, "%lu", mail->unseen);
4514 timed_thread_unlock(mail->p_timed_thread);
4518 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4520 if (mail && mail->p_timed_thread) {
4521 timed_thread_lock(mail->p_timed_thread);
4522 snprintf(p, p_max_size, "%.1f",
4523 mail->used / 1024.0 / 1024.0);
4524 timed_thread_unlock(mail->p_timed_thread);
4528 if (obj->data.fs != NULL) {
4529 if (obj->data.fs->size == 0) {
4531 if(output_methods & TO_X) {
4532 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4535 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4536 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4542 if(output_methods & TO_X) {
4543 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4544 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4545 obj->data.fs->size));
4548 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4549 new_bar_in_shell(p, p_max_size,
4550 (int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4558 if (obj->data.fs != NULL) {
4559 human_readable(obj->data.fs->avail, p, 255);
4563 if (obj->data.fs != NULL) {
4566 if (obj->data.fs->size) {
4567 val = obj->data.fs->avail * 100 / obj->data.fs->size;
4570 percent_print(p, p_max_size, val);
4574 if (obj->data.fs != NULL) {
4575 human_readable(obj->data.fs->size, p, 255);
4579 if (obj->data.fs != NULL)
4580 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4583 if (obj->data.fs != NULL) {
4584 human_readable(obj->data.fs->size - obj->data.fs->free, p,
4589 if (obj->data.fs != NULL) {
4590 if (obj->data.fs->size == 0) {
4592 if(output_methods & TO_X) {
4593 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4596 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4597 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4603 if(output_methods & TO_X) {
4604 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4605 (int) (obj->data.fsbar.fs->avail * 255 /
4606 obj->data.fs->size));
4609 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4610 new_bar_in_shell(p, p_max_size,
4611 (int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4619 if (obj->data.fs != NULL) {
4622 if (obj->data.fs->size) {
4623 val = obj->data.fs->free
4628 percent_print(p, p_max_size, 100 - val);
4632 float *v = info.loadavg;
4634 if (obj->data.loadavg[2]) {
4635 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4636 v[obj->data.loadavg[0] - 1],
4637 v[obj->data.loadavg[1] - 1],
4638 v[obj->data.loadavg[2] - 1]);
4639 } else if (obj->data.loadavg[1]) {
4640 snprintf(p, p_max_size, "%.2f %.2f",
4641 v[obj->data.loadavg[0] - 1],
4642 v[obj->data.loadavg[1] - 1]);
4643 } else if (obj->data.loadavg[0]) {
4644 snprintf(p, p_max_size, "%.2f",
4645 v[obj->data.loadavg[0] - 1]);
4649 new_goto(p, obj->data.i);
4652 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4656 new_hr(p, obj->data.i);
4660 if (cur->nameserver_info.nscount > obj->data.i)
4661 snprintf(p, p_max_size, "%s",
4662 cur->nameserver_info.ns_list[obj->data.i]);
4666 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4667 snprintf(p, p_max_size, "%s", skill);
4672 if (obj->data.curl.uri != NULL) {
4673 ccurl_process_info(p, p_max_size, obj->data.curl.uri, obj->data.curl.interval);
4675 ERR("error processing Curl data");
4681 if (obj->data.rss.uri != NULL) {
4682 rss_process_info(p, p_max_size, obj->data.rss.uri, obj->data.rss.action, obj->data.rss.act_par, obj->data.rss.interval, obj->data.rss.nrspaces);
4684 ERR("error processing RSS data");
4690 if (obj->data.weather.uri != NULL) {
4691 weather_process_info(p, p_max_size, obj->data.weather.uri, obj->data.weather.data_type, obj->data.weather.interval);
4693 ERR("error processing weather data, check that you have a valid XOAP key if using XOAP.");
4699 char *str = llua_getstring(obj->data.s);
4701 snprintf(p, p_max_size, "%s", str);
4706 char *str = llua_getstring(obj->data.s);
4714 if (llua_getnumber(obj->data.s, &per)) {
4716 if(output_methods & TO_X) {
4717 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4720 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4721 new_bar_in_shell(p, p_max_size, per, obj->a);
4730 if (llua_getnumber(obj->data.s, &per)) {
4731 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4732 per, obj->e, 1, obj->char_a, obj->char_b);
4737 if (llua_getnumber(obj->data.s, &per)) {
4738 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4742 #endif /* HAVE_LUA */
4747 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4748 if (obj->data.hddtemp.temp)
4749 free(obj->data.hddtemp.temp);
4750 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4751 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4752 obj->data.hddtemp.update_time = current_update_time;
4754 if (!obj->data.hddtemp.temp) {
4755 snprintf(p, p_max_size, "N/A");
4757 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4758 unit = obj->data.hddtemp.temp[0];
4760 if (*endptr != '\0')
4761 snprintf(p, p_max_size, "N/A");
4762 else if (unit == 'C')
4763 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4764 else if (unit == 'F')
4765 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4767 snprintf(p, p_max_size, "N/A");
4772 new_offset(p, obj->data.i);
4775 new_voffset(p, obj->data.i);
4781 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4782 obj->data.sysfs.devtype, obj->data.sysfs.type);
4784 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4786 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4787 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4788 } else if (r >= 100.0 || r == 0) {
4789 snprintf(p, p_max_size, "%d", (int) r);
4791 snprintf(p, p_max_size, "%.1f", r);
4797 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4798 obj->data.sysfs.devtype, obj->data.sysfs.type);
4800 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4802 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4803 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4804 } else if (r >= 100.0 || r == 0) {
4805 snprintf(p, p_max_size, "%d", (int) r);
4807 snprintf(p, p_max_size, "%.1f", r);
4813 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4814 obj->data.sysfs.devtype, obj->data.sysfs.type);
4816 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4818 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4819 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4820 } else if (r >= 100.0 || r == 0) {
4821 snprintf(p, p_max_size, "%d", (int) r);
4823 snprintf(p, p_max_size, "%.1f", r);
4826 #endif /* __linux__ */
4828 new_alignr(p, obj->data.i);
4831 new_alignc(p, obj->data.i);
4834 char buf[max_user_text];
4835 struct information *tmp_info =
4836 malloc(sizeof(struct information));
4837 memcpy(tmp_info, cur, sizeof(struct information));
4838 generate_text_internal(buf, max_user_text,
4839 *obj->sub, tmp_info);
4841 if (strlen(buf) != 0) {
4847 char expression[max_user_text];
4849 struct information *tmp_info;
4851 tmp_info = malloc(sizeof(struct information));
4852 memcpy(tmp_info, cur, sizeof(struct information));
4853 generate_text_internal(expression, max_user_text,
4854 *obj->sub, tmp_info);
4855 DBGP("parsed arg into '%s'", expression);
4857 val = compare(expression);
4859 ERR("compare failed for expression '%s'",
4867 if (obj->data.ifblock.str
4868 && !check_contains(obj->data.ifblock.s,
4869 obj->data.ifblock.str)) {
4871 } else if (obj->data.ifblock.s
4872 && access(obj->data.ifblock.s, F_OK)) {
4877 if ((obj->data.ifblock.s)
4878 && (!check_mount(obj->data.ifblock.s))) {
4884 if (!get_process_by_name(obj->data.ifblock.s)) {
4886 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4891 #if defined(__linux__)
4893 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4897 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4900 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4905 human_readable(cur->mem * 1024, p, 255);
4908 human_readable(cur->memeasyfree * 1024, p, 255);
4911 human_readable(cur->memfree * 1024, p, 255);
4914 human_readable(cur->memmax * 1024, p, 255);
4918 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4922 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4923 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4928 if(output_methods & TO_X) {
4929 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4930 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4933 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4934 new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
4941 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4942 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4943 100, 1, obj->char_a, obj->char_b);
4948 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4951 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4954 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4958 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4959 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4962 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4963 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4966 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4967 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4970 OBJ(if_mixer_mute) {
4971 if (!mixer_is_mute(obj->data.ifblock.i)) {
4976 #define NOT_IN_X "Not running in X"
4978 if(x_initialised != YES) {
4979 strncpy(p, NOT_IN_X, p_max_size);
4981 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4984 OBJ(monitor_number) {
4985 if(x_initialised != YES) {
4986 strncpy(p, NOT_IN_X, p_max_size);
4988 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4992 if(x_initialised != YES) {
4993 strncpy(p, NOT_IN_X, p_max_size);
4995 snprintf(p, p_max_size, "%d", cur->x11.desktop.current);
4998 OBJ(desktop_number) {
4999 if(x_initialised != YES) {
5000 strncpy(p, NOT_IN_X, p_max_size);
5002 snprintf(p, p_max_size, "%d", cur->x11.desktop.number);
5006 if(x_initialised != YES) {
5007 strncpy(p, NOT_IN_X, p_max_size);
5008 }else if(cur->x11.desktop.name != NULL) {
5009 strncpy(p, cur->x11.desktop.name, p_max_size);
5016 update_mail_count(&obj->data.local_mail);
5017 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5020 update_mail_count(&obj->data.local_mail);
5021 snprintf(p, p_max_size, "%d",
5022 obj->data.local_mail.new_mail_count);
5025 update_mail_count(&obj->data.local_mail);
5026 snprintf(p, p_max_size, "%d",
5027 obj->data.local_mail.seen_mail_count);
5030 update_mail_count(&obj->data.local_mail);
5031 snprintf(p, p_max_size, "%d",
5032 obj->data.local_mail.unseen_mail_count);
5034 OBJ(flagged_mails) {
5035 update_mail_count(&obj->data.local_mail);
5036 snprintf(p, p_max_size, "%d",
5037 obj->data.local_mail.flagged_mail_count);
5039 OBJ(unflagged_mails) {
5040 update_mail_count(&obj->data.local_mail);
5041 snprintf(p, p_max_size, "%d",
5042 obj->data.local_mail.unflagged_mail_count);
5044 OBJ(forwarded_mails) {
5045 update_mail_count(&obj->data.local_mail);
5046 snprintf(p, p_max_size, "%d",
5047 obj->data.local_mail.forwarded_mail_count);
5049 OBJ(unforwarded_mails) {
5050 update_mail_count(&obj->data.local_mail);
5051 snprintf(p, p_max_size, "%d",
5052 obj->data.local_mail.unforwarded_mail_count);
5054 OBJ(replied_mails) {
5055 update_mail_count(&obj->data.local_mail);
5056 snprintf(p, p_max_size, "%d",
5057 obj->data.local_mail.replied_mail_count);
5059 OBJ(unreplied_mails) {
5060 update_mail_count(&obj->data.local_mail);
5061 snprintf(p, p_max_size, "%d",
5062 obj->data.local_mail.unreplied_mail_count);
5065 update_mail_count(&obj->data.local_mail);
5066 snprintf(p, p_max_size, "%d",
5067 obj->data.local_mail.draft_mail_count);
5069 OBJ(trashed_mails) {
5070 update_mail_count(&obj->data.local_mail);
5071 snprintf(p, p_max_size, "%d",
5072 obj->data.local_mail.trashed_mail_count);
5075 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5077 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5080 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5083 new_outline(p, obj->data.l);
5086 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
5088 OBJ(running_processes) {
5089 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
5092 snprintf(p, p_max_size, "%s", obj->data.s);
5096 new_bg(p, obj->data.l);
5099 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5103 human_readable(cur->swap * 1024, p, 255);
5106 human_readable(cur->swapfree * 1024, p, 255);
5109 human_readable(cur->swapmax * 1024, p, 255);
5112 if (cur->swapmax == 0) {
5113 strncpy(p, "No swap", p_max_size);
5115 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
5120 if(output_methods & TO_X) {
5121 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5122 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5125 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5126 new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
5132 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5135 time_t t = time(NULL);
5136 struct tm *tm = localtime(&t);
5138 setlocale(LC_TIME, "");
5139 strftime(p, p_max_size, obj->data.s, tm);
5142 time_t t = time(NULL);
5143 struct tm *tm = gmtime(&t);
5145 strftime(p, p_max_size, obj->data.s, tm);
5152 if (obj->data.tztime.tz) {
5153 oldTZ = getenv("TZ");
5154 setenv("TZ", obj->data.tztime.tz, 1);
5160 setlocale(LC_TIME, "");
5161 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5163 setenv("TZ", oldTZ, 1);
5168 // Needless to free oldTZ since getenv gives ptr to static data
5171 human_readable(obj->data.net->recv, p, 255);
5174 human_readable(obj->data.net->trans, p, 255);
5177 snprintf(p, p_max_size, "%d", total_updates);
5180 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
5185 human_readable(obj->data.net->trans_speed, p, 255);
5188 spaced_print(p, p_max_size, "%.1f", 8,
5189 obj->data.net->trans_speed / 1024.0);
5193 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5194 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
5198 format_seconds_short(p, p_max_size, (int) cur->uptime);
5201 format_seconds(p, p_max_size, (int) cur->uptime);
5204 snprintf(p, p_max_size, "%s", cur->users.names);
5207 snprintf(p, p_max_size, "%s", cur->users.terms);
5210 snprintf(p, p_max_size, "%s", cur->users.times);
5213 snprintf(p, p_max_size, "%d", cur->users.number);
5215 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5216 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5220 msg = get_apm_adapter();
5221 snprintf(p, p_max_size, "%s", msg);
5224 OBJ(apm_battery_life) {
5227 msg = get_apm_battery_life();
5228 snprintf(p, p_max_size, "%s", msg);
5231 OBJ(apm_battery_time) {
5234 msg = get_apm_battery_time();
5235 snprintf(p, p_max_size, "%s", msg);
5238 #endif /* __FreeBSD__ __OpenBSD__ */
5241 #define mpd_printf(fmt, val) \
5242 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
5243 #define mpd_sprintf(val) { \
5244 if (!obj->data.i || obj->data.i > p_max_size) \
5245 mpd_printf("%s", val); \
5247 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
5252 mpd_sprintf(artist);
5256 mpd_printf("%s", random);
5258 mpd_printf("%s", repeat);
5266 mpd_printf("%d", volume);
5268 mpd_printf("%d", bitrate);
5270 mpd_printf("%s", status);
5272 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
5275 format_media_player_time(p, p_max_size, mpd_get_info()->length);
5278 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
5282 if(output_methods & TO_X) {
5283 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5284 (int) (mpd_get_info()->progress * 255.0f));
5287 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5288 new_bar_in_shell(p, p_max_size, (int) (mpd_get_info()->progress * 100.0f), obj->data.pair.a);
5294 struct mpd_s *mpd = mpd_get_info();
5295 int len = obj->data.i;
5296 if (len == 0 || len > p_max_size)
5299 memset(p, 0, p_max_size);
5300 if (mpd->artist && *mpd->artist &&
5301 mpd->title && *mpd->title) {
5302 snprintf(p, len, "%s - %s", mpd->artist,
5304 } else if (mpd->title && *mpd->title) {
5305 snprintf(p, len, "%s", mpd->title);
5306 } else if (mpd->artist && *mpd->artist) {
5307 snprintf(p, len, "%s", mpd->artist);
5308 } else if (mpd->file && *mpd->file) {
5309 snprintf(p, len, "%s", mpd->file);
5314 OBJ(if_mpd_playing) {
5315 if (!mpd_get_info()->is_playing) {
5324 #define MOC_PRINT(t, a) \
5325 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
5327 MOC_PRINT(state, "??");
5330 MOC_PRINT(file, "no file");
5333 MOC_PRINT(title, "no title");
5336 MOC_PRINT(artist, "no artist");
5339 MOC_PRINT(song, "no song");
5342 MOC_PRINT(album, "no album");
5344 OBJ(moc_totaltime) {
5345 MOC_PRINT(totaltime, "0:00");
5348 MOC_PRINT(timeleft, "0:00");
5351 MOC_PRINT(curtime, "0:00");
5354 MOC_PRINT(bitrate, "0Kbps");
5357 MOC_PRINT(rate, "0KHz");
5363 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5366 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5369 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5372 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5374 OBJ(xmms2_comment) {
5375 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5378 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5381 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5384 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5386 OBJ(xmms2_tracknr) {
5387 if (cur->xmms2.tracknr != -1) {
5388 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5391 OBJ(xmms2_bitrate) {
5392 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5395 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5398 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5400 OBJ(xmms2_elapsed) {
5401 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5402 (cur->xmms2.elapsed / 1000) % 60);
5404 OBJ(xmms2_duration) {
5405 snprintf(p, p_max_size, "%02d:%02d",
5406 cur->xmms2.duration / 60000,
5407 (cur->xmms2.duration / 1000) % 60);
5409 OBJ(xmms2_percent) {
5410 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5414 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5415 (int) (cur->xmms2.progress * 255.0f));
5418 OBJ(xmms2_playlist) {
5419 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5421 OBJ(xmms2_timesplayed) {
5422 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5425 if (strlen(cur->xmms2.title) < 2
5426 && strlen(cur->xmms2.title) < 2) {
5427 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5429 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5433 OBJ(if_xmms2_connected) {
5434 if (cur->xmms2.conn_state != 1) {
5440 OBJ(audacious_status) {
5441 snprintf(p, p_max_size, "%s",
5442 cur->audacious.items[AUDACIOUS_STATUS]);
5444 OBJ(audacious_title) {
5445 snprintf(p, cur->audacious.max_title_len > 0
5446 ? cur->audacious.max_title_len : p_max_size, "%s",
5447 cur->audacious.items[AUDACIOUS_TITLE]);
5449 OBJ(audacious_length) {
5450 snprintf(p, p_max_size, "%s",
5451 cur->audacious.items[AUDACIOUS_LENGTH]);
5453 OBJ(audacious_length_seconds) {
5454 snprintf(p, p_max_size, "%s",
5455 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5457 OBJ(audacious_position) {
5458 snprintf(p, p_max_size, "%s",
5459 cur->audacious.items[AUDACIOUS_POSITION]);
5461 OBJ(audacious_position_seconds) {
5462 snprintf(p, p_max_size, "%s",
5463 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5465 OBJ(audacious_bitrate) {
5466 snprintf(p, p_max_size, "%s",
5467 cur->audacious.items[AUDACIOUS_BITRATE]);
5469 OBJ(audacious_frequency) {
5470 snprintf(p, p_max_size, "%s",
5471 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5473 OBJ(audacious_channels) {
5474 snprintf(p, p_max_size, "%s",
5475 cur->audacious.items[AUDACIOUS_CHANNELS]);
5477 OBJ(audacious_filename) {
5478 snprintf(p, p_max_size, "%s",
5479 cur->audacious.items[AUDACIOUS_FILENAME]);
5481 OBJ(audacious_playlist_length) {
5482 snprintf(p, p_max_size, "%s",
5483 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5485 OBJ(audacious_playlist_position) {
5486 snprintf(p, p_max_size, "%s",
5487 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5489 OBJ(audacious_main_volume) {
5490 snprintf(p, p_max_size, "%s",
5491 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5494 OBJ(audacious_bar) {
5498 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5499 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5500 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5503 #endif /* AUDACIOUS */
5507 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5510 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5513 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5516 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5519 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5522 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5525 /* we have four different types of top (top, top_mem,
5526 * top_time and top_io). To avoid having almost-same code four
5527 * times, we have this special handler. */
5530 parse_top_args("top", obj->data.top.s, obj);
5531 if (!needed) needed = cur->cpu;
5533 parse_top_args("top_mem", obj->data.top.s, obj);
5534 if (!needed) needed = cur->memu;
5536 parse_top_args("top_time", obj->data.top.s, obj);
5537 if (!needed) needed = cur->time;
5540 parse_top_args("top_io", obj->data.top.s, obj);
5541 if (!needed) needed = cur->io;
5544 if (needed[obj->data.top.num]) {
5547 switch (obj->data.top.type) {
5549 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5550 needed[obj->data.top.num]->name);
5553 snprintf(p, 7, "%6.2f",
5554 needed[obj->data.top.num]->amount);
5557 snprintf(p, 6, "%5i",
5558 needed[obj->data.top.num]->pid);
5561 snprintf(p, 7, "%6.2f",
5562 needed[obj->data.top.num]->totalmem);
5565 timeval = format_time(
5566 needed[obj->data.top.num]->total_cpu_time, 9);
5567 snprintf(p, 10, "%9s", timeval);
5571 human_readable(needed[obj->data.top.num]->rss,
5575 human_readable(needed[obj->data.top.num]->vsize,
5579 case TOP_READ_BYTES:
5580 human_readable(needed[obj->data.top.num]->read_bytes / update_interval,
5583 case TOP_WRITE_BYTES:
5584 human_readable(needed[obj->data.top.num]->write_bytes / update_interval,
5588 snprintf(p, 7, "%6.2f",
5589 needed[obj->data.top.num]->io_perc);
5595 print_tail_object(obj, p, p_max_size);
5597 print_head_object(obj, p, p_max_size);
5599 FILE *fp = open_file(obj->data.s, &obj->a);
5602 /* FIXME: use something more general (see also tail.c, head.c */
5603 #define BUFSZ 0x1000
5608 while(fgets(buf, BUFSZ, fp) != NULL){
5609 for(j = 0; buf[j] != 0; j++) {
5610 if(buf[j] == '\n') {
5615 sprintf(p, "%d", lines);
5618 sprintf(p, "File Unreadable");
5623 FILE *fp = open_file(obj->data.s, &obj->a);
5628 char inword = FALSE;
5631 while(fgets(buf, BUFSZ, fp) != NULL){
5632 for(j = 0; buf[j] != 0; j++) {
5633 if(!isspace(buf[j])) {
5634 if(inword == FALSE) {
5643 sprintf(p, "%d", words);
5646 sprintf(p, "File Unreadable");
5649 #ifdef TCP_PORT_MONITOR
5651 tcp_portmon_action(p, p_max_size,
5652 &obj->data.tcp_port_monitor);
5654 #endif /* TCP_PORT_MONITOR */
5658 iconv_converting = 1;
5659 iconv_selected = obj->a;
5662 iconv_converting = 0;
5665 #endif /* HAVE_ICONV */
5667 OBJ(entropy_avail) {
5668 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5671 percent_print(p, p_max_size,
5672 cur->entropy.entropy_avail *
5673 100 / cur->entropy.poolsize);
5675 OBJ(entropy_poolsize) {
5676 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5679 double entropy_perc;
5681 entropy_perc = (double) cur->entropy.entropy_avail /
5682 (double) cur->entropy.poolsize;
5684 if(output_methods & TO_X) {
5685 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5688 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5689 new_bar_in_shell(p, p_max_size, (int) (entropy_perc * 100.0f), obj->a);
5698 s = smapi_get_val(obj->data.s);
5699 snprintf(p, p_max_size, "%s", s);
5703 OBJ(if_smapi_bat_installed) {
5705 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5706 if(!smapi_bat_installed(idx)) {
5710 ERR("argument to if_smapi_bat_installed must be an integer");
5712 OBJ(smapi_bat_perc) {
5714 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5715 val = smapi_bat_installed(idx) ?
5716 smapi_get_bat_int(idx, "remaining_percent") : 0;
5717 percent_print(p, p_max_size, val);
5719 ERR("argument to smapi_bat_perc must be an integer");
5721 OBJ(smapi_bat_temp) {
5723 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5724 val = smapi_bat_installed(idx) ?
5725 smapi_get_bat_int(idx, "temperature") : 0;
5726 /* temperature is in milli degree celsius */
5727 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5729 ERR("argument to smapi_bat_temp must be an integer");
5731 OBJ(smapi_bat_power) {
5733 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5734 val = smapi_bat_installed(idx) ?
5735 smapi_get_bat_int(idx, "power_now") : 0;
5736 /* power_now is in mW, set to W with one digit precision */
5737 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5739 ERR("argument to smapi_bat_power must be an integer");
5742 OBJ(smapi_bat_bar) {
5743 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5744 new_bar(p, obj->a, obj->b, (int)
5745 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5747 new_bar(p, obj->a, obj->b, 0);
5752 //blinking like this can look a bit ugly if the chars in the font don't have the same width
5753 char buf[max_user_text];
5756 generate_text_internal(buf, max_user_text, *obj->sub, cur);
5757 snprintf(p, p_max_size, "%s", buf);
5758 if(total_updates % 2) {
5759 for(j=0; p[j] != 0; j++) {
5765 char buf[max_user_text];
5767 char unit[16]; // 16 because we can also have long names (like mega-bytes)
5769 generate_text_internal(buf, max_user_text, *obj->sub, cur);
5770 if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
5771 if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
5772 else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
5773 else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
5774 else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
5775 else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
5777 snprintf(p, p_max_size, "%s", buf);
5780 unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
5782 char buf[max_user_text];
5783 generate_text_internal(buf, max_user_text,
5785 for(j = 0; buf[j] != 0; j++) {
5787 case '\n': //place all the lines behind each other with LINESEPARATOR between them
5788 #define LINESEPARATOR '|'
5789 buf[j]=LINESEPARATOR;
5796 //no scrolling necessary if the length of the text to scroll is too short
5797 if (strlen(buf) - colorchanges <= obj->data.scroll.show) {
5798 snprintf(p, p_max_size, "%s", buf);
5801 //make sure a colorchange at the front is not part of the string we are going to show
5802 while(*(buf + obj->data.scroll.start) == SPECIAL_CHAR) {
5803 obj->data.scroll.start++;
5805 //place all chars that should be visible in p, including colorchanges
5806 for(j=0; j < obj->data.scroll.show + visibcolorchanges; j++) {
5807 p[j] = *(buf + obj->data.scroll.start + j);
5808 if(p[j] == SPECIAL_CHAR) {
5809 visibcolorchanges++;
5811 //if there is still room fill it with spaces
5814 for(; j < obj->data.scroll.show + visibcolorchanges; j++) {
5818 //count colorchanges in front of the visible part and place that many colorchanges in front of the visible part
5819 for(j = 0; j < obj->data.scroll.start; j++) {
5820 if(buf[j] == SPECIAL_CHAR) frontcolorchanges++;
5822 pwithcolors=malloc(strlen(p) + 1 + colorchanges - visibcolorchanges);
5823 for(j = 0; j < frontcolorchanges; j++) {
5824 pwithcolors[j] = SPECIAL_CHAR;
5827 strcat(pwithcolors,p);
5828 strend = strlen(pwithcolors);
5829 //and place the colorchanges not in front or in the visible part behind the visible part
5830 for(j = 0; j < colorchanges - frontcolorchanges - visibcolorchanges; j++) {
5831 pwithcolors[strend + j] = SPECIAL_CHAR;
5833 pwithcolors[strend + j] = 0;
5834 strcpy(p, pwithcolors);
5837 obj->data.scroll.start += obj->data.scroll.step;
5838 if(buf[obj->data.scroll.start] == 0){
5839 obj->data.scroll.start = 0;
5842 //reset color when scroll is finished
5843 new_fg(p + strlen(p), obj->data.scroll.resetcolor);
5847 char buf[2][max_user_text];
5854 struct llrows* next;
5856 struct llrows *ll_rows[2], *current[2];
5857 struct text_object * objsub = obj->sub;
5860 for(i=0; i<2; i++) {
5863 ll_rows[i] = malloc(sizeof(struct llrows));
5864 current[i] = ll_rows[i];
5865 for(j=0; j<i; j++) objsub = objsub->sub;
5866 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5867 for(j=0; buf[i][j] != 0; j++) {
5868 if(buf[i][j] == '\t') buf[i][j] = ' ';
5869 if(buf[i][j] == '\n') {
5871 current[i]->row = strdup(buf[i]+nextstart);
5872 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5873 current[i]->next = malloc(sizeof(struct llrows));
5874 current[i] = current[i]->next;
5879 current[i]->row = strdup(buf[i]+nextstart);
5880 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5881 current[i]->next = NULL;
5882 current[i] = ll_rows[i];
5884 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5886 strcat(p, current[0]->row);
5887 i=strlen(current[0]->row);
5889 while(i < longest) {
5894 strcat(p, obj->data.combine.seperation);
5895 strcat(p, current[1]->row);
5899 #pragma omp parallel for schedule(dynamic,10)
5900 #endif /* HAVE_OPENMP */
5901 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5904 #pragma omp parallel for schedule(dynamic,10)
5905 #endif /* HAVE_OPENMP */
5906 for(i=0; i<2; i++) {
5907 while(ll_rows[i] != NULL) {
5908 current[i]=ll_rows[i];
5909 free(current[i]->row);
5910 ll_rows[i]=current[i]->next;
5917 int value = get_nvidia_value(obj->data.nvidia.type, display);
5919 snprintf(p, p_max_size, "N/A");
5920 else if (obj->data.nvidia.type == NV_TEMP)
5921 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5922 else if (obj->data.nvidia.print_as_float &&
5923 value > 0 && value < 100)
5924 snprintf(p, p_max_size, "%.1f", (float)value);
5926 snprintf(p, p_max_size, "%d", value);
5931 /* This is just a meta-object to set host:port */
5934 snprintf(p, p_max_size, "%s",
5935 cur->apcupsd.items[APCUPSD_NAME]);
5937 OBJ(apcupsd_model) {
5938 snprintf(p, p_max_size, "%s",
5939 cur->apcupsd.items[APCUPSD_MODEL]);
5941 OBJ(apcupsd_upsmode) {
5942 snprintf(p, p_max_size, "%s",
5943 cur->apcupsd.items[APCUPSD_UPSMODE]);
5945 OBJ(apcupsd_cable) {
5946 snprintf(p, p_max_size, "%s",
5947 cur->apcupsd.items[APCUPSD_CABLE]);
5949 OBJ(apcupsd_status) {
5950 snprintf(p, p_max_size, "%s",
5951 cur->apcupsd.items[APCUPSD_STATUS]);
5953 OBJ(apcupsd_linev) {
5954 snprintf(p, p_max_size, "%s",
5955 cur->apcupsd.items[APCUPSD_LINEV]);
5958 snprintf(p, p_max_size, "%s",
5959 cur->apcupsd.items[APCUPSD_LOAD]);
5961 OBJ(apcupsd_loadbar) {
5964 if(output_methods & TO_X) {
5965 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5966 new_bar(p, obj->a, obj->b, (int) progress);
5969 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5970 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5971 new_bar_in_shell(p, p_max_size, (int) progress, obj->a);
5977 OBJ(apcupsd_loadgraph) {
5979 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5980 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5981 (int)progress, 100, 1, obj->char_a, obj->char_b);
5983 OBJ(apcupsd_loadgauge) {
5985 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5986 new_gauge(p, obj->a, obj->b,
5990 OBJ(apcupsd_charge) {
5991 snprintf(p, p_max_size, "%s",
5992 cur->apcupsd.items[APCUPSD_CHARGE]);
5994 OBJ(apcupsd_timeleft) {
5995 snprintf(p, p_max_size, "%s",
5996 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5999 snprintf(p, p_max_size, "%s",
6000 cur->apcupsd.items[APCUPSD_TEMP]);
6002 OBJ(apcupsd_lastxfer) {
6003 snprintf(p, p_max_size, "%s",
6004 cur->apcupsd.items[APCUPSD_LASTXFER]);
6006 #endif /* APCUPSD */
6013 unsigned int a = strlen(p);
6016 if (a > 0 && iconv_converting && iconv_selected > 0
6017 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6019 size_t dummy1, dummy2;
6021 const char *ptr = buff_in;
6023 char *ptr = buff_in;
6027 dummy1 = dummy2 = a;
6029 strncpy(buff_in, p, p_max_size);
6031 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6032 while (dummy1 > 0) {
6033 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6036 ERR("Iconv codeset conversion failed");
6041 /* It is nessecary when we are converting from multibyte to
6042 * singlebyte codepage */
6045 #endif /* HAVE_ICONV */
6046 if (obj->type != OBJ_text) {
6047 substitute_newlines(p, a - 2);
6055 /* load any new fonts we may have had */
6056 if (need_to_load_fonts) {
6062 void evaluate(char *text, char *buffer)
6064 struct information *tmp_info;
6065 struct text_object subroot;
6067 tmp_info = malloc(sizeof(struct information));
6068 memcpy(tmp_info, &info, sizeof(struct information));
6069 parse_conky_vars(&subroot, text, buffer, tmp_info);
6070 DBGP("evaluated '%s' to '%s'", text, buffer);
6072 free_text_objects(&subroot, 1);
6076 double current_update_time, next_update_time, last_update_time;
6078 static void generate_text(void)
6080 struct information *cur = &info;
6087 current_update_time = get_time();
6091 /* add things to the buffer */
6097 generate_text_internal(p, max_user_text, global_root_object, cur);
6099 if (stuff_in_uppercase) {
6102 tmp_p = text_buffer;
6104 *tmp_p = toupper(*tmp_p);
6109 next_update_time += update_interval;
6110 if (next_update_time < get_time()) {
6111 next_update_time = get_time() + update_interval;
6112 } else if (next_update_time > get_time() + update_interval) {
6113 next_update_time = get_time() + update_interval;
6115 last_update_time = current_update_time;
6119 static inline int get_string_width(const char *s)
6122 if (output_methods & TO_X) {
6123 return *s ? calc_text_width(s, strlen(s)) : 0;
6130 static int get_string_width_special(char *s, int special_index)
6137 if ((output_methods & TO_X) == 0) {
6138 return (s) ? strlen(s) : 0;
6145 p = strndup(s, text_buffer_size);
6149 if (*p == SPECIAL_CHAR) {
6150 /* shift everything over by 1 so that the special char
6151 * doesn't mess up the size calculation */
6152 for (i = 0; i < (long)strlen(p); i++) {
6153 *(p + i) = *(p + i + 1);
6155 if (specials[special_index + idx].type == GRAPH
6156 || specials[special_index + idx].type == GAUGE
6157 || specials[special_index + idx].type == BAR) {
6158 width += specials[special_index + idx].width;
6161 } else if (*p == SECRIT_MULTILINE_CHAR) {
6168 if (strlen(final) > 1) {
6169 width += calc_text_width(final, strlen(final));
6175 static int text_size_updater(char *s, int special_index);
6177 int last_font_height;
6178 static void update_text_area(void)
6182 if ((output_methods & TO_X) == 0)
6184 /* update text size if it isn't fixed */
6189 text_width = minimum_width;
6191 last_font_height = font_height();
6192 for_each_line(text_buffer, text_size_updater);
6194 if (text_height < minimum_height) {
6195 text_height = minimum_height;
6197 if (text_width > maximum_width && maximum_width > 0) {
6198 text_width = maximum_width;
6202 /* get text position on workarea */
6203 switch (text_alignment) {
6210 x = workarea[2] - text_width - gap_x;
6215 x = workarea[2] / 2 - text_width / 2 - gap_x;
6222 y = workarea[3] - text_height - gap_y;
6226 x = workarea[2] - text_width - gap_x;
6227 y = workarea[3] - text_height - gap_y;
6231 x = workarea[2] / 2 - text_width / 2 - gap_x;
6232 y = workarea[3] - text_height - gap_y;
6237 y = workarea[3] / 2 - text_height / 2 - gap_y;
6241 x = workarea[2] - text_width - gap_x;
6242 y = workarea[3] / 2 - text_height / 2 - gap_y;
6246 case NONE: // Let the WM manage the window
6257 if (own_window && !fixed_pos) {
6260 text_start_x = window.border_inner_margin + window.border_outer_margin + window.border_width;
6261 text_start_y = window.border_inner_margin + window.border_outer_margin + window.border_width;
6262 window.x = x - window.border_inner_margin - window.border_outer_margin - window.border_width;
6263 window.y = y - window.border_inner_margin - window.border_outer_margin - window.border_width;
6267 /* If window size doesn't match to workarea's size,
6268 * then window probably includes panels (gnome).
6269 * Blah, doesn't work on KDE. */
6270 if (workarea[2] != window.width || workarea[3] != window.height) {
6279 /* update lua window globals */
6280 llua_update_window_table(text_start_x, text_start_y, text_width, text_height);
6281 #endif /* HAVE_LUA */
6286 static int cur_x, cur_y; /* current x and y for drawing */
6288 //draw_mode also without X11 because we only need to print to stdout with FG
6289 static int draw_mode; /* FG, BG or OUTLINE */
6291 static long current_color;
6293 static int text_size_updater(char *s, int special_index)
6298 if ((output_methods & TO_X) == 0)
6300 /* get string widths and skip specials */
6303 if (*p == SPECIAL_CHAR) {
6305 w += get_string_width(s);
6308 if (specials[special_index].type == BAR
6309 || specials[special_index].type == GAUGE
6310 || specials[special_index].type == GRAPH) {
6311 w += specials[special_index].width;
6312 if (specials[special_index].height > last_font_height) {
6313 last_font_height = specials[special_index].height;
6314 last_font_height += font_height();
6316 } else if (specials[special_index].type == OFFSET) {
6317 if (specials[special_index].arg > 0) {
6318 w += specials[special_index].arg;
6320 } else if (specials[special_index].type == VOFFSET) {
6321 last_font_height += specials[special_index].arg;
6322 } else if (specials[special_index].type == GOTO) {
6323 if (specials[special_index].arg > cur_x) {
6324 w = (int) specials[special_index].arg;
6326 } else if (specials[special_index].type == TAB) {
6327 int start = specials[special_index].arg;
6328 int step = specials[special_index].width;
6330 if (!step || step < 0) {
6333 w += step - (cur_x - text_start_x - start) % step;
6334 } else if (specials[special_index].type == FONT) {
6335 selected_font = specials[special_index].font_added;
6336 if (font_height() > last_font_height) {
6337 last_font_height = font_height();
6343 } else if (*p == SECRIT_MULTILINE_CHAR) {
6346 lw = get_string_width(s);
6347 *p = SECRIT_MULTILINE_CHAR;
6349 w = lw > w ? lw : w;
6350 text_height += last_font_height;
6354 w += get_string_width(s);
6355 if (w > text_width) {
6358 if (text_width > maximum_width && maximum_width) {
6359 text_width = maximum_width;
6362 text_height += last_font_height;
6363 last_font_height = font_height();
6364 return special_index;
6367 static inline void set_foreground_color(long c)
6369 if ((output_methods & TO_X) == 0)
6372 XSetForeground(display, window.gc, c);
6376 static void draw_string(const char *s)
6378 int i, i2, pos, width_of_s;
6386 width_of_s = get_string_width(s);
6387 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
6389 if (extra_newline) fputc('\n', stdout);
6390 fflush(stdout); /* output immediately, don't buffer */
6392 if ((output_methods & TO_STDERR) && draw_mode == FG) {
6393 fprintf(stderr, "%s\n", s);
6394 fflush(stderr); /* output immediately, don't buffer */
6396 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
6397 fprintf(overwrite_fpointer, "%s\n", s);
6399 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
6400 fprintf(append_fpointer, "%s\n", s);
6402 memset(tmpstring1, 0, text_buffer_size);
6403 memset(tmpstring2, 0, text_buffer_size);
6404 strncpy(tmpstring1, s, text_buffer_size - 1);
6409 if (output_methods & TO_X) {
6410 max = ((text_width - width_of_s) / get_string_width(" "));
6413 /* This code looks for tabs in the text and coverts them to spaces.
6414 * The trick is getting the correct number of spaces, and not going
6415 * over the window's size without forcing the window larger. */
6416 for (i = 0; i < (int) text_buffer_size; i++) {
6417 if (tmpstring1[i] == '\t') {
6419 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6420 /* guard against overrun */
6421 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6426 /* guard against overrun */
6427 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6432 if (output_methods & TO_X) {
6433 if (text_width == maximum_width) {
6434 /* this means the text is probably pushing the limit,
6435 * so we'll chop it */
6436 while (cur_x + get_string_width(tmpstring2) - text_start_x
6437 > maximum_width && strlen(tmpstring2) > 0) {
6438 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6445 if (output_methods & TO_X) {
6451 c.pixel = current_color;
6452 XQueryColor(display, DefaultColormap(display, screen), &c);
6455 c2.color.red = c.red;
6456 c2.color.green = c.green;
6457 c2.color.blue = c.blue;
6458 c2.color.alpha = fonts[selected_font].font_alpha;
6460 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6461 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6463 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6464 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6469 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6472 cur_x += width_of_s;
6475 memcpy(tmpstring1, s, text_buffer_size);
6479 int draw_each_line_inner(char *s, int special_index, int last_special_applied)
6481 int font_h = font_height();
6485 int last_special_needed = -1;
6486 int orig_special_index = special_index;
6488 cur_x = text_start_x;
6489 cur_y += font_ascent();
6492 if (*p == SECRIT_MULTILINE_CHAR) {
6493 /* special newline marker for multiline objects */
6498 if (*p == SPECIAL_CHAR || last_special_applied > -1) {
6501 /* draw string before special, unless we're dealing multiline
6503 if (last_special_applied > -1) {
6504 special_index = last_special_applied;
6512 switch (specials[special_index].type) {
6513 case HORIZONTAL_LINE:
6515 int h = specials[special_index].height;
6516 int mid = font_ascent() / 2;
6518 w = text_start_x + text_width - cur_x;
6520 XSetLineAttributes(display, window.gc, h, LineSolid,
6521 CapButt, JoinMiter);
6522 XDrawLine(display, window.drawable, window.gc, cur_x,
6523 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6529 int h = specials[special_index].height;
6530 int tmp_s = specials[special_index].arg;
6531 int mid = font_ascent() / 2;
6532 char ss[2] = { tmp_s, tmp_s };
6534 w = text_start_x + text_width - cur_x - 1;
6535 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6536 CapButt, JoinMiter);
6537 XSetDashes(display, window.gc, 0, ss, 2);
6538 XDrawLine(display, window.drawable, window.gc, cur_x,
6539 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6545 int h, bar_usage, by;
6546 if (cur_x - text_start_x > maximum_width
6547 && maximum_width > 0) {
6550 h = specials[special_index].height;
6551 bar_usage = specials[special_index].arg;
6552 by = cur_y - (font_ascent() / 2) - 1;
6557 w = specials[special_index].width;
6559 w = text_start_x + text_width - cur_x - 1;
6565 XSetLineAttributes(display, window.gc, 1, LineSolid,
6566 CapButt, JoinMiter);
6568 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6570 XFillRectangle(display, window.drawable, window.gc, cur_x,
6571 by, w * bar_usage / 255, h);
6579 case GAUGE: /* new GAUGE */
6582 unsigned long last_colour = current_color;
6584 float angle, px, py;
6588 if (cur_x - text_start_x > maximum_width
6589 && maximum_width > 0) {
6593 h = specials[special_index].height;
6594 by = cur_y - (font_ascent() / 2) - 1;
6599 w = specials[special_index].width;
6601 w = text_start_x + text_width - cur_x - 1;
6607 XSetLineAttributes(display, window.gc, 1, LineSolid,
6608 CapButt, JoinMiter);
6610 XDrawArc(display, window.drawable, window.gc,
6611 cur_x, by, w, h * 2, 0, 180*64);
6614 usage = specials[special_index].arg;
6615 angle = (M_PI)*(float)(usage)/255.;
6616 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6617 py = (float)(by+(h))-(float)(h)*sin(angle);
6619 XDrawLine(display, window.drawable, window.gc,
6620 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6628 set_foreground_color(last_colour);
6636 int h, by, i = 0, j = 0;
6638 unsigned long last_colour = current_color;
6639 unsigned long *tmpcolour = 0;
6640 if (cur_x - text_start_x > maximum_width
6641 && maximum_width > 0) {
6644 h = specials[special_index].height;
6645 by = cur_y - (font_ascent() / 2) - 1;
6650 w = specials[special_index].width;
6652 w = text_start_x + text_width - cur_x - 1;
6657 if (draw_graph_borders) {
6658 XSetLineAttributes(display, window.gc, 1, LineSolid,
6659 CapButt, JoinMiter);
6660 XDrawRectangle(display, window.drawable, window.gc,
6663 XSetLineAttributes(display, window.gc, 1, LineSolid,
6664 CapButt, JoinMiter);
6666 if (specials[special_index].last_colour != 0
6667 || specials[special_index].first_colour != 0) {
6668 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6671 for (i = w - 2; i > -1; i--) {
6672 if (specials[special_index].last_colour != 0
6673 || specials[special_index].first_colour != 0) {
6674 if (specials[special_index].tempgrad) {
6677 (int)((float)(w - 2) - specials[special_index].graph[j] *
6678 (w - 2) / (float)specials[special_index].graph_scale)
6682 (int)((float)(w - 2) - specials[special_index].graph[j] *
6683 (w - 2) / (float)specials[special_index].graph_scale)
6686 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6688 (int)((float)(w - 2) - specials[special_index].graph[j] *
6689 (w - 2) / (float)specials[special_index].graph_scale)
6693 #endif /* DEBUG_lol */
6694 XSetForeground(display, window.gc, tmpcolour[
6695 (int)((float)(w - 2) - specials[special_index].graph[j] *
6696 (w - 2) / (float)specials[special_index].graph_scale)
6699 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6702 /* this is mugfugly, but it works */
6703 XDrawLine(display, window.drawable, window.gc,
6704 cur_x + i + 1, by + h, cur_x + i + 1,
6705 round_to_int((double)by + h - specials[special_index].graph[j] *
6706 (h - 1) / specials[special_index].graph_scale));
6707 if ((w - i) / ((float) (w - 2) /
6708 (specials[special_index].graph_width)) > j
6709 && j < MAX_GRAPH_DEPTH - 3) {
6713 if (tmpcolour) free(tmpcolour);
6718 /* if (draw_mode == BG) {
6719 set_foreground_color(default_bg_color);
6720 } else if (draw_mode == OUTLINE) {
6721 set_foreground_color(default_out_color);
6723 set_foreground_color(default_fg_color);
6725 if (show_graph_range) {
6728 unsigned short int seconds = update_interval * w;
6734 unsigned short int timeunits;
6736 timeunits = seconds / 86400; seconds %= 86400;
6737 if (timeunits > 0) {
6738 asprintf(&tmp_day_str, "%dd", timeunits);
6740 tmp_day_str = strdup("");
6742 timeunits = seconds / 3600; seconds %= 3600;
6743 if (timeunits > 0) {
6744 asprintf(&tmp_hour_str, "%dh", timeunits);
6746 tmp_hour_str = strdup("");
6748 timeunits = seconds / 60; seconds %= 60;
6749 if (timeunits > 0) {
6750 asprintf(&tmp_min_str, "%dm", timeunits);
6752 tmp_min_str = strdup("");
6755 asprintf(&tmp_sec_str, "%ds", seconds);
6757 tmp_sec_str = strdup("");
6759 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6760 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6762 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6764 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6765 cur_y += font_h / 2;
6766 draw_string(tmp_str);
6772 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6776 cur_x += font_ascent() / 2;
6777 cur_y += font_h / 2;
6779 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6781 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6782 draw_string(tmp_str);
6788 set_foreground_color(last_colour);
6794 int old = font_ascent();
6796 cur_y -= font_ascent();
6797 selected_font = specials[special_index].font_added;
6799 if (cur_y + font_ascent() < cur_y + old) {
6802 cur_y += font_ascent();
6804 font_h = font_height();
6808 if (draw_mode == FG) {
6809 set_foreground_color(specials[special_index].arg);
6814 if (draw_mode == BG) {
6815 set_foreground_color(specials[special_index].arg);
6820 if (draw_mode == OUTLINE) {
6821 set_foreground_color(specials[special_index].arg);
6826 w += specials[special_index].arg;
6827 last_special_needed = special_index;
6831 cur_y += specials[special_index].arg;
6835 if (specials[special_index].arg >= 0) {
6836 cur_x = (int) specials[special_index].arg;
6838 last_special_needed = special_index;
6843 int start = specials[special_index].arg;
6844 int step = specials[special_index].width;
6846 if (!step || step < 0) {
6849 w = step - (cur_x - text_start_x - start) % step;
6850 last_special_needed = special_index;
6856 /* TODO: add back in "+ window.border_inner_margin" to the end of
6858 int pos_x = text_start_x + text_width -
6859 get_string_width_special(s, special_index);
6861 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6862 "get_string_width(p) %i gap_x %i "
6863 "specials[special_index].arg %i window.border_inner_margin %i "
6864 "window.border_width %i\n", pos_x, text_start_x, text_width,
6865 cur_x, get_string_width_special(s), gap_x,
6866 specials[special_index].arg, window.border_inner_margin,
6867 window.border_width); */
6868 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6869 cur_x = pos_x - specials[special_index].arg;
6871 last_special_needed = special_index;
6877 int pos_x = (text_width) / 2 - get_string_width_special(s,
6878 special_index) / 2 - (cur_x -
6880 /* int pos_x = text_start_x + text_width / 2 -
6881 get_string_width_special(s) / 2; */
6883 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6884 "get_string_width(p) %i gap_x %i "
6885 "specials[special_index].arg %i\n", pos_x, text_start_x,
6886 text_width, cur_x, get_string_width(s), gap_x,
6887 specials[special_index].arg); */
6888 if (pos_x > specials[special_index].arg) {
6889 w = pos_x - specials[special_index].arg;
6891 last_special_needed = special_index;
6898 if (special_index != last_special_applied) {
6901 special_index = orig_special_index;
6902 last_special_applied = -1;
6910 cur_y += font_descent();
6911 if (recurse && *recurse) {
6912 special_index = draw_each_line_inner(recurse, special_index, last_special_needed);
6913 *(recurse - 1) = SECRIT_MULTILINE_CHAR;
6915 return special_index;
6919 static int draw_line(char *s, int special_index)
6922 if ((output_methods & TO_X) == 0) {
6925 //'special_index - special_index' instead of 0 otherwise gcc complains about not using special_index when build without X11
6926 return special_index - special_index;
6930 /* find specials and draw stuff */
6931 return draw_each_line_inner(s, special_index, -1);
6935 static void draw_text(void)
6939 llua_draw_pre_hook();
6940 #endif /* HAVE_LUA */
6941 if (output_methods & TO_X) {
6942 cur_y = text_start_y;
6945 if (draw_borders && window.border_width > 0) {
6946 if (stippled_borders) {
6947 char ss[2] = { stippled_borders, stippled_borders };
6948 XSetLineAttributes(display, window.gc, window.border_width, LineOnOffDash,
6949 CapButt, JoinMiter);
6950 XSetDashes(display, window.gc, 0, ss, 2);
6952 XSetLineAttributes(display, window.gc, window.border_width, LineSolid,
6953 CapButt, JoinMiter);
6956 XDrawRectangle(display, window.drawable, window.gc,
6957 text_start_x - window.border_inner_margin - window.border_width,
6958 text_start_y - window.border_inner_margin - window.border_width,
6959 text_width + window.border_inner_margin * 2 + window.border_width * 2,
6960 text_height + window.border_inner_margin * 2 + window.border_width * 2);
6967 for_each_line(text_buffer, draw_line);
6968 #if defined(HAVE_LUA) && defined(X11)
6969 llua_draw_post_hook();
6970 #endif /* HAVE_LUA */
6973 static void draw_stuff(void)
6975 if (overwrite_file) {
6976 overwrite_fpointer = fopen(overwrite_file, "w");
6977 if(!overwrite_fpointer)
6978 ERR("Can't overwrite '%s' anymore", overwrite_file);
6981 append_fpointer = fopen(append_file, "a");
6982 if(!append_fpointer)
6983 ERR("Can't append '%s' anymore", append_file);
6986 if (output_methods & TO_X) {
6988 if (draw_shades && !draw_outline) {
6991 set_foreground_color(default_bg_color);
7002 for (i = -1; i < 2; i++) {
7003 for (j = -1; j < 2; j++) {
7004 if (i == 0 && j == 0) {
7009 set_foreground_color(default_out_color);
7010 draw_mode = OUTLINE;
7018 set_foreground_color(default_fg_color);
7024 if (output_methods & TO_X) {
7029 swap.swap_window = window.window;
7030 swap.swap_action = XdbeBackground;
7031 XdbeSwapBuffers(display, &swap, 1);
7036 if(overwrite_fpointer) {
7037 fclose(overwrite_fpointer);
7038 overwrite_fpointer = 0;
7040 if(append_fpointer) {
7041 fclose(append_fpointer);
7042 append_fpointer = 0;
7047 static void clear_text(int exposures)
7051 /* The swap action is XdbeBackground, which clears */
7055 if (display && window.window) { // make sure these are !null
7056 /* there is some extra space for borders and outlines */
7057 XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width,
7058 text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width,
7059 text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
7060 text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, exposures ? True : 0);
7065 static int need_to_update;
7067 /* update_text() generates new text and clears old text area */
7068 static void update_text(void)
7075 if (output_methods & TO_X)
7081 #ifdef HAVE_SYS_INOTIFY_H
7085 static void main_loop(void)
7088 #ifdef SIGNAL_BLOCKING
7089 sigset_t newmask, oldmask;
7092 #ifdef HAVE_SYS_INOTIFY_H
7093 int inotify_config_wd = -1;
7094 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
7095 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
7096 char inotify_buff[INOTIFY_BUF_LEN];
7097 #endif /* HAVE_SYS_INOTIFY_H */
7100 #ifdef SIGNAL_BLOCKING
7101 sigemptyset(&newmask);
7102 sigaddset(&newmask, SIGINT);
7103 sigaddset(&newmask, SIGTERM);
7104 sigaddset(&newmask, SIGUSR1);
7107 last_update_time = 0.0;
7108 next_update_time = get_time();
7110 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
7113 #ifdef SIGNAL_BLOCKING
7114 /* block signals. we will inspect for pending signals later */
7115 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7116 CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
7121 if (output_methods & TO_X) {
7124 /* wait for X event or timeout */
7126 if (!XPending(display)) {
7130 t = next_update_time - get_time();
7134 } else if (t > update_interval) {
7135 t = update_interval;
7138 tv.tv_sec = (long) t;
7139 tv.tv_usec = (long) (t * 1000000) % 1000000;
7141 FD_SET(ConnectionNumber(display), &fdsr);
7143 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7145 if (errno != EINTR) {
7146 ERR("can't select(): %s", strerror(errno));
7156 if (need_to_update) {
7158 int wx = window.x, wy = window.y;
7168 /* resize window if it isn't right size */
7170 && (text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2 != window.width
7171 || text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2 != window.height)) {
7172 window.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7173 window.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7174 XResizeWindow(display, window.window, window.width,
7176 set_transparent_background(window.window);
7181 /* move window if it isn't in right position */
7182 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7183 XMoveWindow(display, window.window, window.x, window.y);
7188 if (changed && window.type == TYPE_PANEL) {
7191 fprintf(stderr, PACKAGE_NAME": defining struts\n");
7194 switch (text_alignment) {
7221 set_struts(sidenum);
7232 r.x = text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width;
7233 r.y = text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width;
7234 r.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7235 r.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7236 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7241 /* handle X events */
7242 while (XPending(display)) {
7245 XNextEvent(display, &ev);
7252 r.width = ev.xexpose.width;
7253 r.height = ev.xexpose.height;
7254 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7258 case PropertyNotify:
7260 if ( ev.xproperty.state == PropertyNewValue ) {
7261 get_x11_desktop_info( ev.xproperty.display, ev.xproperty.atom );
7267 case ReparentNotify:
7268 /* set background to ParentRelative for all parents */
7270 set_transparent_background(window.window);
7274 case ConfigureNotify:
7276 /* if window size isn't what expected, set fixed size */
7277 if (ev.xconfigure.width != window.width
7278 || ev.xconfigure.height != window.height) {
7279 if (window.width != 0 && window.height != 0) {
7283 /* clear old stuff before screwing up
7288 XWindowAttributes attrs;
7289 if (XGetWindowAttributes(display,
7290 window.window, &attrs)) {
7291 window.width = attrs.width;
7292 window.height = attrs.height;
7296 text_width = window.width - window.border_inner_margin * 2 - window.border_outer_margin * 2 - window.border_width * 2;
7297 text_height = window.height - window.border_inner_margin * 2 - window.border_outer_margin * 2 - window.border_width * 2;
7298 if (text_width > maximum_width
7299 && maximum_width > 0) {
7300 text_width = maximum_width;
7304 /* if position isn't what expected, set fixed pos
7305 * total_updates avoids setting fixed_pos when window
7306 * is set to weird locations when started */
7307 /* // this is broken
7308 if (total_updates >= 2 && !fixed_pos
7309 && (window.x != ev.xconfigure.x
7310 || window.y != ev.xconfigure.y)
7311 && (ev.xconfigure.x != 0
7312 || ev.xconfigure.y != 0)) {
7320 /* if an ordinary window with decorations */
7321 if ((window.type == TYPE_NORMAL)
7322 && (!TEST_HINT(window.hints,
7323 HINT_UNDECORATED))) {
7324 /* allow conky to hold input focus. */
7327 /* forward the click to the desktop window */
7328 XUngrabPointer(display, ev.xbutton.time);
7329 ev.xbutton.window = window.desktop;
7330 ev.xbutton.x = ev.xbutton.x_root;
7331 ev.xbutton.y = ev.xbutton.y_root;
7332 XSendEvent(display, ev.xbutton.window, False,
7333 ButtonPressMask, &ev);
7334 XSetInputFocus(display, ev.xbutton.window,
7335 RevertToParent, ev.xbutton.time);
7342 /* if an ordinary window with decorations */
7343 if ((window.type == TYPE_NORMAL)
7344 && (!TEST_HINT(window.hints,
7345 HINT_UNDECORATED))) {
7346 /* allow conky to hold input focus. */
7349 /* forward the release to the desktop window */
7350 ev.xbutton.window = window.desktop;
7351 ev.xbutton.x = ev.xbutton.x_root;
7352 ev.xbutton.y = ev.xbutton.y_root;
7353 XSendEvent(display, ev.xbutton.window, False,
7354 ButtonReleaseMask, &ev);
7363 if (ev.type == x11_stuff.event_base + XDamageNotify) {
7364 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7366 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
7367 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
7369 #endif /* HAVE_XDAMAGE */
7375 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
7376 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
7377 #endif /* HAVE_XDAMAGE */
7379 /* XDBE doesn't seem to provide a way to clear the back buffer without
7380 * interfering with the front buffer, other than passing XdbeBackground
7381 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7382 * redraw the text even if it wasn't part of the exposed area. OTOH,
7383 * if we're not going to call draw_stuff at all, then no swap happens
7384 * and we can safely do nothing. */
7386 if (!XEmptyRegion(x11_stuff.region)) {
7391 r.x = text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width;
7392 r.y = text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width;
7393 r.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7394 r.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7395 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7398 XSetRegion(display, window.gc, x11_stuff.region);
7401 XftDrawSetClip(window.xftdraw, x11_stuff.region);
7405 cimlib_render(text_start_x, text_start_y, window.width, window.height);
7408 XDestroyRegion(x11_stuff.region);
7409 x11_stuff.region = XCreateRegion();
7413 t = (next_update_time - get_time()) * 1000000;
7414 if(t > 0) usleep((useconds_t)t);
7421 #ifdef SIGNAL_BLOCKING
7422 /* unblock signals of interest and let handler fly */
7423 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7424 CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
7428 switch (g_signal_pending) {
7431 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7436 ERR("received SIGINT or SIGTERM to terminate. bye!");
7439 if (output_methods & TO_X) {
7440 XDestroyRegion(x11_stuff.region);
7441 x11_stuff.region = NULL;
7443 XDamageDestroy(display, x11_stuff.damage);
7444 XFixesDestroyRegion(display, x11_stuff.region2);
7445 XFixesDestroyRegion(display, x11_stuff.part);
7446 #endif /* HAVE_XDAMAGE */
7452 if(overwrite_file) {
7453 free(overwrite_file);
7462 /* Reaching here means someone set a signal
7463 * (SIGXXXX, signal_handler), but didn't write any code
7465 * If you don't want to handle a signal, don't set a handler on
7466 * it in the first place. */
7467 if (g_signal_pending) {
7468 ERR("ignoring signal (%d)", g_signal_pending);
7472 #ifdef HAVE_SYS_INOTIFY_H
7473 if (inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
7474 inotify_config_wd = inotify_add_watch(inotify_fd,
7478 if (inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
7479 int len = 0, idx = 0;
7481 struct timeval time_to_wait;
7483 FD_ZERO(&descriptors);
7484 FD_SET(inotify_fd, &descriptors);
7486 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
7488 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
7489 if (FD_ISSET(inotify_fd, &descriptors)) {
7490 /* process inotify events */
7491 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
7492 while (len > 0 && idx < len) {
7493 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
7494 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
7495 /* current_config should be reloaded */
7496 ERR("'%s' modified, reloading...", current_config);
7498 if (ev->mask & IN_IGNORED) {
7499 /* for some reason we get IN_IGNORED here
7500 * sometimes, so we need to re-add the watch */
7501 inotify_config_wd = inotify_add_watch(inotify_fd,
7508 llua_inotify_query(ev->wd, ev->mask);
7510 #endif /* HAVE_LUA */
7511 idx += INOTIFY_EVENT_SIZE + ev->len;
7515 #endif /* HAVE_SYS_INOTIFY_H */
7517 g_signal_pending = 0;
7519 clean_up(NULL, NULL);
7521 #ifdef HAVE_SYS_INOTIFY_H
7522 if (inotify_fd != -1) {
7523 inotify_rm_watch(inotify_fd, inotify_config_wd);
7525 inotify_fd = inotify_config_wd = 0;
7527 #endif /* HAVE_SYS_INOTIFY_H */
7530 static void load_config_file(const char *);
7532 static void load_config_file_x11(const char *);
7534 void initialisation(int argc, char** argv);
7536 /* reload the config file */
7537 static void reload_config(void)
7539 char *current_config_copy = strdup(current_config);
7540 clean_up(NULL, NULL);
7541 current_config = current_config_copy;
7542 initialisation(argc_copy, argv_copy);
7545 void clean_up(void *memtofree1, void* memtofree2)
7554 timed_thread_destroy_registered_threads();
7556 if (info.cpu_usage) {
7557 free(info.cpu_usage);
7558 info.cpu_usage = NULL;
7561 if (x_initialised == YES) {
7564 if(x11_stuff.region) {
7565 XDestroyRegion(x11_stuff.region);
7566 x11_stuff.region = NULL;
7568 XClearWindow(display, RootWindow(display, screen));
7569 XCloseDisplay(display);
7571 if(info.x11.desktop.all_names) {
7572 free(info.x11.desktop.all_names);
7573 info.x11.desktop.all_names = NULL;
7575 if (info.x11.desktop.name) {
7576 free(info.x11.desktop.name);
7577 info.x11.desktop.name = NULL;
7581 free(fonts); //in set_default_configurations a font is set but not loaded
7587 for (i = 0; i < MAX_TEMPLATES; i++) {
7594 free_text_objects(&global_root_object, 0);
7613 free(current_config);
7616 #ifdef TCP_PORT_MONITOR
7617 tcp_portmon_clear();
7626 weather_free_info();
7630 #endif /* HAVE_LUA */
7633 for (i = 0; i < special_count; i++) {
7634 if (specials[i].type == GRAPH) {
7635 free(specials[i].graph);
7643 clear_diskio_stats();
7644 if(global_cpu != NULL) {
7650 static int string_to_bool(const char *s)
7653 // Assumes an option without a true/false means true
7655 } else if (strcasecmp(s, "yes") == EQUAL) {
7657 } else if (strcasecmp(s, "true") == EQUAL) {
7659 } else if (strcasecmp(s, "1") == EQUAL) {
7666 static enum alignment string_to_alignment(const char *s)
7668 if (strcasecmp(s, "top_left") == EQUAL) {
7670 } else if (strcasecmp(s, "top_right") == EQUAL) {
7672 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7674 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7676 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7677 return BOTTOM_RIGHT;
7678 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7679 return BOTTOM_MIDDLE;
7680 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7682 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7683 return MIDDLE_RIGHT;
7684 } else if (strcasecmp(s, "tl") == EQUAL) {
7686 } else if (strcasecmp(s, "tr") == EQUAL) {
7688 } else if (strcasecmp(s, "tm") == EQUAL) {
7690 } else if (strcasecmp(s, "bl") == EQUAL) {
7692 } else if (strcasecmp(s, "br") == EQUAL) {
7693 return BOTTOM_RIGHT;
7694 } else if (strcasecmp(s, "bm") == EQUAL) {
7695 return BOTTOM_MIDDLE;
7696 } else if (strcasecmp(s, "ml") == EQUAL) {
7698 } else if (strcasecmp(s, "mr") == EQUAL) {
7699 return MIDDLE_RIGHT;
7700 } else if (strcasecmp(s, "none") == EQUAL) {
7708 static void set_default_configurations_for_x(void)
7710 default_fg_color = WhitePixel(display, screen);
7711 default_bg_color = BlackPixel(display, screen);
7712 default_out_color = BlackPixel(display, screen);
7713 color0 = default_fg_color;
7714 color1 = default_fg_color;
7715 color2 = default_fg_color;
7716 color3 = default_fg_color;
7717 color4 = default_fg_color;
7718 color5 = default_fg_color;
7719 color6 = default_fg_color;
7720 color7 = default_fg_color;
7721 color8 = default_fg_color;
7722 color9 = default_fg_color;
7723 current_text_color = default_fg_color;
7727 static void set_default_configurations(void)
7735 fork_to_background = 0;
7736 total_run_times = 0;
7737 info.cpu_avg_samples = 2;
7738 info.net_avg_samples = 2;
7739 info.diskio_avg_samples = 2;
7744 format_human_readable = 1;
7751 mpd_env_host = getenv("MPD_HOST");
7752 mpd_env_port = getenv("MPD_PORT");
7754 if (!mpd_env_host || !strlen(mpd_env_host)) {
7755 mpd_set_host("localhost");
7757 /* MPD_HOST environment variable is set */
7758 char *mpd_hostpart = strchr(mpd_env_host, '@');
7759 if (!mpd_hostpart) {
7760 mpd_set_host(mpd_env_host);
7762 /* MPD_HOST contains a password */
7763 char mpd_password[mpd_hostpart - mpd_env_host + 1];
7764 snprintf(mpd_password, mpd_hostpart - mpd_env_host + 1, "%s", mpd_env_host);
7766 if (!strlen(mpd_hostpart + 1)) {
7767 mpd_set_host("localhost");
7769 mpd_set_host(mpd_hostpart + 1);
7772 mpd_set_password(mpd_password, 1);
7777 if (!mpd_env_port || mpd_set_port(mpd_env_port)) {
7778 /* failed to set port from environment variable */
7779 mpd_set_port("6600");
7783 info.xmms2.artist = NULL;
7784 info.xmms2.album = NULL;
7785 info.xmms2.title = NULL;
7786 info.xmms2.genre = NULL;
7787 info.xmms2.comment = NULL;
7788 info.xmms2.url = NULL;
7789 info.xmms2.status = NULL;
7790 info.xmms2.playlist = NULL;
7792 use_spacer = NO_SPACER;
7794 output_methods = TO_X;
7796 output_methods = TO_STDOUT;
7799 show_graph_scale = 0;
7800 show_graph_range = 0;
7803 draw_graph_borders = 1;
7805 set_first_font("6x10");
7813 window.type = TYPE_NORMAL;
7815 strcpy(window.class_name, PACKAGE_NAME);
7816 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7818 stippled_borders = 0;
7819 window.border_inner_margin = 3;
7820 window.border_outer_margin = 1;
7821 window.border_width = 1;
7822 text_alignment = BOTTOM_LEFT;
7823 info.x11.monitor.number = 1;
7824 info.x11.monitor.current = 0;
7825 info.x11.desktop.current = 1;
7826 info.x11.desktop.number = 1;
7827 info.x11.desktop.nitems = 0;
7828 info.x11.desktop.all_names = NULL;
7829 info.x11.desktop.name = NULL;
7832 for (i = 0; i < MAX_TEMPLATES; i++) {
7835 template[i] = strdup("");
7838 free(current_mail_spool);
7842 variable_substitute(MAIL_FILE, buf, 256);
7843 if (buf[0] != '\0') {
7844 current_mail_spool = strndup(buf, text_buffer_size);
7849 update_interval = 3.0;
7850 info.music_player_interval = 1.0;
7851 stuff_in_uppercase = 0;
7852 info.users.number = 1;
7854 #ifdef TCP_PORT_MONITOR
7855 /* set default connection limit */
7856 tcp_portmon_set_max_connections(0);
7860 /* returns 1 if you can overwrite or create the file at 'path' */
7861 static _Bool overwrite_works(const char *path)
7865 if (!(filepointer = fopen(path, "w")))
7867 fclose(filepointer);
7871 /* returns 1 if you can append or create the file at 'path' */
7872 static _Bool append_works(const char *path)
7876 if (!(filepointer = fopen(path, "a")))
7878 fclose(filepointer);
7884 /* WARNING, this type not in Xlib spec */
7885 int x11_error_handler(Display *d, XErrorEvent *err)
7886 __attribute__((noreturn));
7887 int x11_error_handler(Display *d, XErrorEvent *err)
7889 ERR("X Error: type %i Display %lx XID %li serial %lu error_code %i request_code %i minor_code %i other Display: %lx\n",
7891 (long unsigned)err->display,
7892 (long)err->resourceid,
7902 int x11_ioerror_handler(Display *d)
7903 __attribute__((noreturn));
7904 int x11_ioerror_handler(Display *d)
7906 ERR("X Error: Display %lx\n",
7913 static void X11_initialisation(void)
7915 if (x_initialised == YES) return;
7916 output_methods |= TO_X;
7918 set_default_configurations_for_x();
7919 x_initialised = YES;
7922 /* WARNING, this type not in Xlib spec */
7923 XSetErrorHandler(&x11_error_handler);
7924 XSetIOErrorHandler(&x11_ioerror_handler);
7928 static char **xargv = 0;
7929 static int xargc = 0;
7931 static void X11_create_window(void)
7933 if (output_methods & TO_X) {
7935 init_window(own_window, text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
7936 text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, set_transparent, background_colour,
7938 #else /* OWN_WINDOW */
7939 init_window(0, text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
7940 text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, set_transparent, 0,
7942 #endif /* OWN_WINDOW */
7946 update_text_area(); /* to position text/window on screen */
7949 if (own_window && !fixed_pos) {
7950 XMoveWindow(display, window.window, window.x, window.y);
7953 set_transparent_background(window.window);
7961 x11_stuff.region = XCreateRegion();
7963 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7964 ERR("Xdamage extension unavailable");
7966 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7967 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7968 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7969 #endif /* HAVE_XDAMAGE */
7972 update_text_area(); /* to get initial size of the window */
7975 /* setup lua window globals */
7976 llua_setup_window_table(text_start_x, text_start_y, text_width, text_height);
7977 #endif /* HAVE_LUA */
7981 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7982 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7983 #define CONF2(a) if (strcasecmp(name, a) == 0)
7984 #define CONF(a) else CONF2(a)
7985 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7986 || strcasecmp(name, b) == 0)
7987 #define CONF_CONTINUE 1
7988 #define CONF_BREAK 2
7989 #define CONF_BUFF_SIZE 512
7991 static FILE *open_config_file(const char *f)
7993 #ifdef CONFIG_OUTPUT
7994 if (!strcmp(f, "==builtin==")) {
7995 return conf_cookie_open();
7997 #endif /* CONFIG_OUTPUT */
7998 return fopen(f, "r");
8001 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
8005 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8008 remove_comments(buf);
8013 while (*p && isspace((int) *p)) {
8017 return CONF_CONTINUE; /* empty line */
8024 while (*p2 && !isspace((int) *p2)) {
8028 *p2 = '\0'; /* break at name's end */
8035 while (*p && isspace((int) *p)) {
8041 p2 = *value + strlen(*value);
8042 while (isspace((int) *(p2 - 1))) {
8051 static void load_config_file(const char *f)
8056 set_default_configurations();
8057 fp = open_config_file(f);
8061 DBGP("reading contents from config file '%s'", f);
8064 char buff[CONF_BUFF_SIZE], *name, *value;
8065 int ret = do_config_step(&line, fp, buff, &name, &value);
8066 if (ret == CONF_BREAK) {
8068 } else if (ret == CONF_CONTINUE) {
8074 /* don't listen if X is already initialised or
8075 * if we already know we don't want it */
8076 if(x_initialised != YES) {
8077 if (string_to_bool(value)) {
8078 output_methods &= TO_X;
8080 output_methods &= ~TO_X;
8081 x_initialised = NEVER;
8086 if (!value || x_initialised == YES) {
8091 disp = strdup(value);
8096 if (window.type == TYPE_DOCK)
8099 #endif /*OWN_WINDOW */
8101 int a = string_to_alignment(value);
8112 CONF("background") {
8113 fork_to_background = string_to_bool(value);
8116 CONF2("background") {
8117 fork_to_background = string_to_bool(value);
8121 CONF("show_graph_scale") {
8122 show_graph_scale = string_to_bool(value);
8124 CONF("show_graph_range") {
8125 show_graph_range = string_to_bool(value);
8127 CONF("border_margin") {
8128 ERR("border_margin is deprecated, please use window.border_inner_margin instead");
8130 window.border_inner_margin = strtol(value, 0, 0);
8131 if (window.border_inner_margin < 0) window.border_inner_margin = 0;
8136 CONF("border_inner_margin") {
8138 window.border_inner_margin = strtol(value, 0, 0);
8139 if (window.border_inner_margin < 0) window.border_inner_margin = 0;
8144 CONF("border_outer_margin") {
8146 window.border_outer_margin = strtol(value, 0, 0);
8147 if (window.border_outer_margin < 0) window.border_outer_margin = 0;
8152 CONF("border_width") {
8154 window.border_width = strtol(value, 0, 0);
8155 if (window.border_width < 0) window.border_width = 0;
8161 #define TEMPLATE_CONF(n) \
8162 CONF("template"#n) { \
8164 free(template[n]); \
8165 template[n] = strdup(value); \
8182 info.mail = parse_mail_args(IMAP_TYPE, value);
8189 info.mail = parse_mail_args(POP3_TYPE, value);
8194 CONF("default_bar_size") {
8197 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
8204 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
8208 CONF("default_graph_size") {
8211 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
8218 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
8221 CONF("default_gauge_size") {
8224 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
8231 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
8238 mpd_set_host(value);
8244 if (value && mpd_set_port(value)) {
8248 CONF("mpd_password") {
8250 mpd_set_password(value, 0);
8256 CONF("music_player_interval") {
8258 info.music_player_interval = strtod(value, 0);
8264 CONF("sensor_device") {
8266 sensor_device = strtol(value, 0, 0);
8272 CONF("cpu_avg_samples") {
8274 cpu_avg_samples = strtol(value, 0, 0);
8275 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8278 info.cpu_avg_samples = cpu_avg_samples;
8284 CONF("net_avg_samples") {
8286 net_avg_samples = strtol(value, 0, 0);
8287 if (net_avg_samples < 1 || net_avg_samples > 14) {
8290 info.net_avg_samples = net_avg_samples;
8296 CONF("diskio_avg_samples") {
8298 diskio_avg_samples = strtol(value, 0, 0);
8299 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
8302 info.diskio_avg_samples = diskio_avg_samples;
8310 CONF("double_buffer") {
8311 use_xdbe = string_to_bool(value);
8315 CONF("override_utf8_locale") {
8316 utf8_mode = string_to_bool(value);
8318 CONF("draw_borders") {
8319 draw_borders = string_to_bool(value);
8321 CONF("draw_graph_borders") {
8322 draw_graph_borders = string_to_bool(value);
8324 CONF("draw_shades") {
8325 draw_shades = string_to_bool(value);
8327 CONF("draw_outline") {
8328 draw_outline = string_to_bool(value);
8331 CONF("out_to_console") {
8332 if(string_to_bool(value))
8333 output_methods |= TO_STDOUT;
8335 CONF("extra_newline") {
8336 extra_newline = string_to_bool(value);
8338 CONF("out_to_stderr") {
8339 if(string_to_bool(value))
8340 output_methods |= TO_STDERR;
8342 CONF("overwrite_file") {
8343 if(overwrite_file) {
8344 free(overwrite_file);
8347 if(overwrite_works(value)) {
8348 overwrite_file = strdup(value);
8349 output_methods |= OVERWRITE_FILE;
8351 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
8353 CONF("append_file") {
8358 if(append_works(value)) {
8359 append_file = strdup(value);
8360 output_methods |= APPEND_FILE;
8362 ERR("append_file won't be able to create/append '%s'", value);
8364 CONF("use_spacer") {
8366 if (strcasecmp(value, "left") == EQUAL) {
8367 use_spacer = LEFT_SPACER;
8368 } else if (strcasecmp(value, "right") == EQUAL) {
8369 use_spacer = RIGHT_SPACER;
8370 } else if (strcasecmp(value, "none") == EQUAL) {
8371 use_spacer = NO_SPACER;
8373 use_spacer = string_to_bool(value);
8374 ERR("use_spacer should have an argument of left, right, or"
8375 " none. '%s' seems to be some form of '%s', so"
8376 " defaulting to %s.", value,
8377 use_spacer ? "true" : "false",
8378 use_spacer ? "right" : "none");
8380 use_spacer = RIGHT_SPACER;
8382 use_spacer = NO_SPACER;
8386 ERR("use_spacer should have an argument. Defaulting to right.");
8387 use_spacer = RIGHT_SPACER;
8393 use_xft = string_to_bool(value);
8397 set_first_font(value);
8401 if (value && font_count >= 0) {
8402 fonts[0].font_alpha = atof(value) * 65535.0;
8409 if (string_to_bool(value)) {
8410 ERR("Xft not enabled at compile time");
8414 /* xftfont silently ignored when no Xft */
8417 /* xftalpha is silently ignored when no Xft */
8422 set_first_font(value);
8430 gap_x = atoi(value);
8437 gap_y = atoi(value);
8443 CONF("mail_spool") {
8447 variable_substitute(value, buffer, 256);
8449 if (buffer[0] != '\0') {
8450 if (current_mail_spool) {
8451 free(current_mail_spool);
8453 current_mail_spool = strndup(buffer, text_buffer_size);
8460 CONF("minimum_size") {
8462 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8464 if (sscanf(value, "%d", &minimum_width) != 1) {
8472 CONF("maximum_width") {
8474 if (sscanf(value, "%d", &maximum_width) != 1) {
8482 CONF("no_buffers") {
8483 no_buffers = string_to_bool(value);
8485 CONF("top_name_width") {
8487 if (sscanf(value, "%u", &top_name_width) != 1) {
8493 if (top_name_width >= max_user_text) {
8494 top_name_width = max_user_text - 1;
8497 CONF("top_cpu_separate") {
8498 cpu_separate = string_to_bool(value);
8500 CONF("short_units") {
8501 short_units = string_to_bool(value);
8503 CONF("format_human_readable") {
8504 format_human_readable = string_to_bool(value);
8506 CONF("pad_percents") {
8507 pad_percents = atoi(value);
8511 CONF("own_window") {
8513 own_window = string_to_bool(value);
8516 CONF("own_window_class") {
8518 memset(window.class_name, 0, sizeof(window.class_name));
8519 strncpy(window.class_name, value,
8520 sizeof(window.class_name) - 1);
8523 CONF("own_window_title") {
8525 memset(window.title, 0, sizeof(window.title));
8526 strncpy(window.title, value, sizeof(window.title) - 1);
8529 CONF("own_window_transparent") {
8531 set_transparent = string_to_bool(value);
8534 CONF("own_window_hints") {
8536 char *p_hint, *p_save;
8537 char delim[] = ", ";
8539 /* tokenize the value into individual hints */
8540 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8542 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8543 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8544 SET_HINT(window.hints, HINT_UNDECORATED);
8545 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8546 SET_HINT(window.hints, HINT_BELOW);
8547 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8548 SET_HINT(window.hints, HINT_ABOVE);
8549 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8550 SET_HINT(window.hints, HINT_STICKY);
8551 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8552 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8553 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8554 SET_HINT(window.hints, HINT_SKIP_PAGER);
8559 p_hint = strtok_r(NULL, delim, &p_save);
8560 } while (p_hint != NULL);
8566 CONF("own_window_type") {
8568 if (strncmp(value, "normal", 6) == EQUAL) {
8569 window.type = TYPE_NORMAL;
8570 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8571 window.type = TYPE_DESKTOP;
8572 } else if (strncmp(value, "dock", 4) == EQUAL) {
8573 window.type = TYPE_DOCK;
8574 text_alignment = TOP_LEFT;
8575 } else if (strncmp(value, "panel", 5) == EQUAL) {
8576 window.type = TYPE_PANEL;
8577 } else if (strncmp(value, "override", 8) == EQUAL) {
8578 window.type = TYPE_OVERRIDE;
8587 CONF("stippled_borders") {
8589 stippled_borders = strtol(value, 0, 0);
8591 stippled_borders = 4;
8595 CONF("imlib_cache_size") {
8597 cimlib_set_cache_size(atoi(value));
8600 CONF("imlib_cache_flush_interval") {
8602 cimlib_set_cache_flush_interval(atoi(value));
8607 CONF("update_interval") {
8609 update_interval = strtod(value, 0);
8613 if (info.music_player_interval == 0) {
8614 // default to update_interval
8615 info.music_player_interval = update_interval;
8618 CONF("total_run_times") {
8620 total_run_times = strtod(value, 0);
8626 stuff_in_uppercase = string_to_bool(value);
8628 CONF("max_specials") {
8630 max_specials = atoi(value);
8635 CONF("max_user_text") {
8637 max_user_text = atoi(value);
8642 CONF("text_buffer_size") {
8644 text_buffer_size = atoi(value);
8645 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8646 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8647 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8655 if (output_methods & TO_X) {
8656 X11_initialisation();
8665 global_text = (char *) malloc(1);
8666 global_text[0] = '\0';
8669 unsigned int l = strlen(global_text);
8671 char buf[CONF_BUFF_SIZE];
8673 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8679 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8687 /* Check for continuation of \\-\n. */
8688 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8689 global_text[l-1] = '\0';
8693 global_text = (char *) realloc(global_text, l + bl + 1);
8694 strcat(global_text, buf);
8696 if (strlen(global_text) > max_user_text) {
8701 if (strlen(global_text) < 1) {
8702 CRIT_ERR(NULL, NULL, "no text supplied in configuration; exiting");
8704 global_text_lines = line + 1;
8707 #ifdef TCP_PORT_MONITOR
8708 CONF("max_port_monitor_connections") {
8710 if (!value || (sscanf(value, "%d", &max) != 1)) {
8711 /* an error. use default, warn and continue. */
8712 tcp_portmon_set_max_connections(0);
8714 } else if (tcp_portmon_set_max_connections(max)) {
8715 /* max is < 0, default has been set*/
8720 CONF("if_up_strictness") {
8722 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8723 ifup_strictness = IFUP_UP;
8724 } else if (strcasecmp(value, "up") == EQUAL) {
8725 ifup_strictness = IFUP_UP;
8726 } else if (strcasecmp(value, "link") == EQUAL) {
8727 ifup_strictness = IFUP_LINK;
8728 } else if (strcasecmp(value, "address") == EQUAL) {
8729 ifup_strictness = IFUP_ADDR;
8731 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8732 ifup_strictness = IFUP_UP;
8736 CONF("temperature_unit") {
8738 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8739 } else if (set_temp_output_unit(value)) {
8740 ERR("temperature_unit: incorrect argument");
8746 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8747 char *skey = malloc(maxlength);
8748 char *svalue = malloc(maxlength);
8750 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8751 oldvalue = getenv(skey);
8752 if (oldvalue == NULL) {
8753 setenv(skey, svalue, 0);
8755 //PS: Don't free oldvalue, it's the real envvar, not a copy
8768 char *ptr = strtok(value, " ");
8771 ptr = strtok(NULL, " ");
8778 CONF("lua_draw_hook_pre") {
8780 llua_set_draw_pre_hook(value);
8785 CONF("lua_draw_hook_post") {
8787 llua_set_draw_post_hook(value);
8793 #endif /* HAVE_LUA */
8805 CONF("default_color"){}
8806 CONF3("default_shade_color", "default_shadecolor"){}
8807 CONF3("default_outline_color", "default_outlinecolor") {}
8808 CONF("own_window_colour") {}
8811 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8817 if (info.music_player_interval == 0) {
8818 // default to update_interval
8819 info.music_player_interval = update_interval;
8821 if (!global_text) { // didn't supply any text
8822 CRIT_ERR(NULL, NULL, "missing text block in configuration; exiting");
8827 static void load_config_file_x11(const char *f)
8832 fp = open_config_file(f);
8836 DBGP("reading contents from config file '%s'", f);
8839 char buff[CONF_BUFF_SIZE], *name, *value;
8840 int ret = do_config_step(&line, fp, buff, &name, &value);
8841 if (ret == CONF_BREAK) {
8843 } else if (ret == CONF_CONTINUE) {
8848 X11_initialisation();
8849 if (x_initialised == YES) {
8851 color0 = get_x11_color(value);
8858 X11_initialisation();
8859 if (x_initialised == YES) {
8861 color1 = get_x11_color(value);
8868 X11_initialisation();
8869 if (x_initialised == YES) {
8871 color2 = get_x11_color(value);
8878 X11_initialisation();
8879 if (x_initialised == YES) {
8881 color3 = get_x11_color(value);
8888 X11_initialisation();
8889 if (x_initialised == YES) {
8891 color4 = get_x11_color(value);
8898 X11_initialisation();
8899 if (x_initialised == YES) {
8901 color5 = get_x11_color(value);
8908 X11_initialisation();
8909 if (x_initialised == YES) {
8911 color6 = get_x11_color(value);
8918 X11_initialisation();
8919 if (x_initialised == YES) {
8921 color7 = get_x11_color(value);
8928 X11_initialisation();
8929 if (x_initialised == YES) {
8931 color8 = get_x11_color(value);
8938 X11_initialisation();
8939 if (x_initialised == YES) {
8941 color9 = get_x11_color(value);
8947 CONF("default_color") {
8948 X11_initialisation();
8949 if (x_initialised == YES) {
8951 default_fg_color = get_x11_color(value);
8957 CONF3("default_shade_color", "default_shadecolor") {
8958 X11_initialisation();
8959 if (x_initialised == YES) {
8961 default_bg_color = get_x11_color(value);
8967 CONF3("default_outline_color", "default_outlinecolor") {
8968 X11_initialisation();
8969 if (x_initialised == YES) {
8971 default_out_color = get_x11_color(value);
8978 CONF("own_window_colour") {
8979 X11_initialisation();
8980 if (x_initialised == YES) {
8982 background_colour = get_x11_color(value);
8984 ERR("Invalid colour for own_window_colour (try omitting the "
8985 "'#' for hex colours");
8991 /* initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod) */
8992 if(output_methods & TO_X) {
8993 X11_initialisation();
9002 #undef CONF_CONTINUE
9003 #undef CONF_BUFF_SIZE
9011 #if defined(WEATHER) && defined(XOAP)
9013 * TODO: make the xoap keys file readable from the config file
9014 * make the keys directly readable from the config file
9015 * make the xoap keys file giveable as a command line option
9017 static void load_xoap_keys(void)
9020 char *par = (char *) malloc(11 * sizeof(char));
9021 char *key = (char *) malloc(17 * sizeof(char));
9023 xoap = (char *) malloc(64 * sizeof(char));
9024 to_real_path(xoap, XOAP_FILE);
9025 fp = fopen(xoap, "r");
9027 if( fscanf(fp, "%10s %16s", par, key) == 2 ) {
9028 strcpy(xoap, "?cc=*&link=xoap&prod=xoap&par=");
9030 strcat(xoap, "&key=");
9032 strcat(xoap, "&unit=m");
9045 #endif /* WEATHER && XOAP */
9047 static void print_help(const char *prog_name) {
9048 printf("Usage: %s [OPTION]...\n"
9049 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
9050 "window. Command line options will override configurations defined in config\n"
9052 " -v, --version version\n"
9053 " -q, --quiet quiet mode\n"
9054 " -D, --debug increase debugging output, ie. -DD for more debugging\n"
9055 " -c, --config=FILE config file to load\n"
9056 #ifdef CONFIG_OUTPUT
9057 " -C, --print-config print the builtin default config to stdout\n"
9058 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
9060 " -d, --daemonize daemonize, fork to background\n"
9061 " -h, --help help\n"
9063 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
9064 " -f, --font=FONT font to use\n"
9065 " -X, --display=DISPLAY X11 display to use\n"
9067 " -o, --own-window create own window to draw\n"
9070 " -b, --double-buffer double buffer (prevents flickering)\n"
9072 " -w, --window-id=WIN_ID window id to draw\n"
9073 " -x X x position\n"
9074 " -y Y y position\n"
9076 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
9077 " -u, --interval=SECS update interval\n"
9078 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
9083 /* : means that character before that takes an argument */
9084 static const char *getopt_string = "vVqdDt:u:i:hc:"
9094 #ifdef CONFIG_OUTPUT
9099 static const struct option longopts[] = {
9100 { "help", 0, NULL, 'h' },
9101 { "version", 0, NULL, 'V' },
9102 { "debug", 0, NULL, 'D' },
9103 { "config", 1, NULL, 'c' },
9104 #ifdef CONFIG_OUTPUT
9105 { "print-config", 0, NULL, 'C' },
9107 { "daemonize", 0, NULL, 'd' },
9109 { "alignment", 1, NULL, 'a' },
9110 { "font", 1, NULL, 'f' },
9111 { "display", 1, NULL, 'X' },
9113 { "own-window", 0, NULL, 'o' },
9116 { "double-buffer", 0, NULL, 'b' },
9118 { "window-id", 1, NULL, 'w' },
9120 { "text", 1, NULL, 't' },
9121 { "interval", 0, NULL, 'u' },
9125 void initialisation(int argc, char **argv) {
9126 struct sigaction act, oact;
9128 load_config_file(current_config);
9130 /* init specials array */
9131 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
9132 ERR("failed to create specials array");
9136 if (current_mail_spool == NULL) {
9139 variable_substitute(MAIL_FILE, buf, 256);
9141 if (buf[0] != '\0') {
9142 current_mail_spool = strndup(buf, text_buffer_size);
9147 /* handle other command line arguments */
9149 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
9150 || defined(__NetBSD__)
9151 optind = optreset = 1;
9156 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9157 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
9158 "kvm_open")) == NULL) {
9159 CRIT_ERR(NULL, NULL, "cannot read kvm");
9164 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
9172 fork_to_background = 1;
9175 global_debug_level++;
9179 set_first_font(optarg);
9182 text_alignment = string_to_alignment(optarg);
9187 disp = strdup(optarg);
9206 global_text = strndup(optarg, max_user_text);
9207 convert_escapes(global_text);
9211 update_interval = strtod(optarg, 0);
9212 if (info.music_player_interval == 0) {
9213 // default to update_interval
9214 info.music_player_interval = update_interval;
9219 total_run_times = strtod(optarg, 0);
9223 gap_x = atoi(optarg);
9227 gap_y = atoi(optarg);
9238 if (output_methods & TO_X) {
9239 load_config_file_x11(current_config);
9243 /* generate text and get initial size */
9244 extract_variable_text(global_text);
9251 if (fork_to_background) {
9256 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
9263 fprintf(stderr, "\n");
9268 /* parent process */
9269 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
9276 text_buffer = malloc(max_user_text);
9277 memset(text_buffer, 0, max_user_text);
9278 tmpstring1 = malloc(text_buffer_size);
9279 memset(tmpstring1, 0, text_buffer_size);
9280 tmpstring2 = malloc(text_buffer_size);
9281 memset(tmpstring2, 0, text_buffer_size);
9286 X11_create_window();
9289 /* Set signal handlers */
9290 act.sa_handler = signal_handler;
9291 sigemptyset(&act.sa_mask);
9294 act.sa_flags |= SA_RESTART;
9297 if ( sigaction(SIGINT, &act, &oact) < 0
9298 || sigaction(SIGUSR1, &act, &oact) < 0
9299 || sigaction(SIGHUP, &act, &oact) < 0
9300 || sigaction(SIGTERM, &act, &oact) < 0) {
9301 ERR("error setting signal handler: %s", strerror(errno));
9306 int main(int argc, char **argv)
9315 g_signal_pending = 0;
9316 max_user_text = MAX_USER_TEXT_DEFAULT;
9318 memset(&info, 0, sizeof(info));
9319 memset(template, 0, sizeof(template));
9322 #ifdef TCP_PORT_MONITOR
9323 /* set default connection limit */
9324 tcp_portmon_set_max_connections(0);
9327 /* handle command line parameters that don't change configs */
9329 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
9330 || ((s = getenv("LANG")) && *s)) {
9331 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
9333 ERR("malloc failed");
9335 for (x = 0; x < strlen(s); x++) {
9336 temp[x] = tolower(s[x]);
9339 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
9345 if (!setlocale(LC_CTYPE, "")) {
9346 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
9350 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
9361 if (current_config) {
9362 free(current_config);
9364 current_config = strndup(optarg, max_user_text);
9367 freopen("/dev/null", "w", stderr);
9370 print_help(argv[0]);
9372 #ifdef CONFIG_OUTPUT
9379 window.window = strtol(optarg, 0, 0);
9388 /* check if specified config file is valid */
9389 if (current_config) {
9391 if (stat(current_config, &sb) ||
9392 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
9393 ERR("invalid configuration file '%s'\n", current_config);
9394 free(current_config);
9399 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
9401 if (!current_config) {
9402 /* load default config file */
9403 char buf[DEFAULT_TEXT_BUFFER_SIZE];
9406 /* Try to use personal config file first */
9407 to_real_path(buf, CONFIG_FILE);
9408 if (buf[0] && (fp = fopen(buf, "r"))) {
9409 current_config = strndup(buf, max_user_text);
9413 /* Try to use system config file if personal config not readable */
9414 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
9415 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
9419 /* No readable config found */
9420 if (!current_config) {
9421 #ifdef CONFIG_OUTPUT
9422 current_config = strdup("==builtin==");
9423 ERR("no readable personal or system-wide config file found,"
9424 " using builtin default");
9426 CRIT_ERR(NULL, NULL, "no readable personal or system-wide config file found");
9427 #endif /* ! CONF_OUTPUT */
9431 #if defined(WEATHER) && defined(XOAP)
9432 /* Load xoap keys, if existing */
9434 #endif /* WEATHER && XOAP */
9436 #ifdef HAVE_SYS_INOTIFY_H
9437 inotify_fd = inotify_init();
9438 #endif /* HAVE_SYS_INOTIFY_H */
9440 initialisation(argc, argv);
9444 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9451 static void signal_handler(int sig)
9453 /* signal handler is light as a feather, as it should be.
9454 * we will poll g_signal_pending with each loop of conky
9455 * and do any signal processing there, NOT here. */
9456 g_signal_pending = sig;