* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
/* debugging level, used by logging.h */
int global_debug_level = 0;
+/* disable inotify auto reload feature if desired */
+int disable_auto_reload = 0;
+
/* two strings for internal use */
static char *tmpstring1, *tmpstring2;
double update_interval_old;
double update_interval_bat;
void *global_cpu = NULL;
+unsigned int max_text_width = 0;
int argc_copy;
char** argv_copy;
# ifdef XFT
" * Xft\n"
# endif /* XFT */
+# ifdef USE_ARGB
+ " * ARGB visual\n"
+# endif /* USE_ARGB */
#endif /* X11 */
"\n Music detection:\n"
#ifdef AUDACIOUS
/* alignments */
enum alignment {
- TOP_LEFT = 1,
+ ALIGNMENT_ERROR,
+ TOP_LEFT,
TOP_RIGHT,
TOP_MIDDLE,
BOTTOM_LEFT,
/* fork? */
static int fork_to_background;
+/* set to 0 after the first time conky is run, so we don't fork again after the
+ * first forking */
+static int first_pass = 1;
+
static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
/* filenames for output */
#define SECRIT_MULTILINE_CHAR '\x02'
-static inline int calc_text_width(const char *s)
+int calc_text_width(const char *s)
{
size_t slen = strlen(s);
get_acpi_fan(p, p_max_size);
}
OBJ(acpiacadapter) {
- get_acpi_ac_adapter(p, p_max_size);
+ get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
}
OBJ(battery) {
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
percent_print(p, p_max_size, get_battery_perct(obj->data.s));
}
OBJ(battery_bar) {
-#ifdef X11
- if(output_methods & TO_X) {
- new_bar(obj, p, get_battery_perct_bar(obj->data.s));
- }else
-#endif /* X11 */
- new_bar_in_shell(obj, p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55);
+ new_bar(obj, p, p_max_size, get_battery_perct_bar(obj->data.s));
}
OBJ(battery_short) {
get_battery_short_status(p, p_max_size, obj->data.s);
print_cmdline_to_pid(obj, p, p_max_size);
}
OBJ(cpu) {
- if (obj->data.i > info.cpu_count) {
- NORM_ERR("obj->data.i %i info.cpu_count %i",
- obj->data.i, info.cpu_count);
- CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
- }
- percent_print(p, p_max_size,
+ if (cur->cpu_usage) {
+ if (obj->data.i > info.cpu_count) {
+ NORM_ERR("obj->data.i %i info.cpu_count %i",
+ obj->data.i, info.cpu_count);
+ CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
+ }
+ percent_print(p, p_max_size,
round_to_int(cur->cpu_usage[obj->data.i] * 100.0));
+ }
}
-#ifdef X11
OBJ(cpugauge)
- new_gauge(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
-#endif /* X11 */
+ new_gauge(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
OBJ(cpubar) {
-#ifdef X11
- if(output_methods & TO_X) {
- new_bar(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
- }else
-#endif /* X11 */
- new_bar_in_shell(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100));
+ new_bar(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
}
#ifdef X11
OBJ(cpugraph) {
- new_graph(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 100));
+ new_graph(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100));
}
OBJ(loadgraph) {
- print_loadgraph(obj, p);
+ print_loadgraph(obj, p, p_max_size);
}
#endif /* X11 */
OBJ(color) {
print_diskiograph(obj, p, p_max_size);
}
OBJ(diskiograph_read) {
- print_diskiograph(obj, p, p_max_size);
+ print_diskiograph_read(obj, p, p_max_size);
}
OBJ(diskiograph_write) {
- print_diskiograph(obj, p, p_max_size);
+ print_diskiograph_write(obj, p, p_max_size);
}
#endif /* X11 */
OBJ(downspeed) {
OBJ(execp) {
print_execp(obj, p, p_max_size);
}
-#ifdef X11
OBJ(execgauge) {
print_execgauge(obj, p, p_max_size);
}
-#endif /* X11 */
OBJ(execbar) {
print_execbar(obj, p, p_max_size);
}
OBJ(execigraph) {
print_execigraph(obj, p, p_max_size);
}
+#endif /* X11 */
OBJ(execigauge) {
print_execigauge(obj, p, p_max_size);
}
-#endif /* X11 */
OBJ(execi) {
print_execi(obj, p, p_max_size);
}
OBJ(lua_graph) {
print_lua_graph(obj, p, p_max_size);
}
+#endif /* X11 */
OBJ(lua_gauge) {
print_lua_gauge(obj, p, p_max_size);
}
-#endif /* X11 */
#endif /* HAVE_LUA */
#ifdef HDDTEMP
OBJ(hddtemp) {
if (cur->memmax)
percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
}
-#ifdef X11
OBJ(memgauge){
- new_gauge(obj, p, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
+ new_gauge(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
}
-#endif /* X11 */
OBJ(membar) {
-#ifdef X11
- if(output_methods & TO_X) {
- new_bar(obj, p, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
- }else
-#endif /* X11 */
- new_bar_in_shell(obj, p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0);
+ new_bar(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
}
#ifdef X11
OBJ(memgraph) {
- new_graph(obj, p, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0);
+ new_graph(obj, p, p_max_size, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0);
}
#endif /* X11 */
/* mixer stuff */
OBJ(mixerr) {
print_mixerr(obj, p, p_max_size);
}
-#ifdef X11
OBJ(mixerbar) {
print_mixer_bar(obj, p, p_max_size);
}
OBJ(mixerrbar) {
print_mixerr_bar(obj, p, p_max_size);
}
-#endif /* X11 */
OBJ(if_mixer_mute) {
if (!check_mixer_muted(obj)) {
DO_JUMP;
}
}
OBJ(swapbar) {
-#ifdef X11
- if(output_methods & TO_X) {
- new_bar(obj, p, cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
- }else
-#endif /* X11 */
- new_bar_in_shell(obj, p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0);
+ new_bar(obj, p, p_max_size, cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
}
OBJ(sysname) {
snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
OBJ(xmms2_percent) {
snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
}
-#ifdef X11
OBJ(xmms2_bar) {
- new_bar(obj, p, (int) (cur->xmms2.progress * 255.0f));
+ new_bar(obj, p, p_max_size, (int) (cur->xmms2.progress * 255.0f));
}
-#endif /* X11 */
OBJ(xmms2_playlist) {
snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
}
snprintf(p, p_max_size, "%s",
cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
}
-#ifdef X11
OBJ(audacious_bar) {
double progress;
progress =
atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
- new_bar(obj, p, (int) (progress * 255.0f));
+ new_bar(obj, p, p_max_size, (int) (progress * 255.0f));
}
-#endif /* X11 */
#endif /* AUDACIOUS */
#ifdef BMPX
OBJ(smapi_bat_power) {
print_smapi_bat_power(obj, p, p_max_size);
}
-#ifdef X11
OBJ(smapi_bat_bar) {
print_smapi_bat_bar(obj, p, p_max_size);
}
-#endif /* X11 */
#endif /* IBM */
OBJ(include) {
if(obj->sub) {
}
OBJ(apcupsd_loadbar) {
double progress;
-#ifdef X11
- if(output_methods & TO_X) {
- progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
- new_bar(obj, p, (int) progress);
- } else
-#endif /* X11 */
- {
- progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
- new_bar_in_shell(obj, p, p_max_size, (int) progress);
- }
+ progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
+ new_bar(obj, p, p_max_size, (int) progress);
}
#ifdef X11
OBJ(apcupsd_loadgraph) {
double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
- new_graph(obj, p, (int)progress);
+ new_graph(obj, p, p_max_size, (int)progress);
}
+#endif /* X11 */
OBJ(apcupsd_loadgauge) {
double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
- new_gauge(obj, p, (int)progress);
+ new_gauge(obj, p, p_max_size, (int)progress);
}
-#endif /* X11 */
OBJ(apcupsd_charge) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_CHARGE]);
tmp_info = malloc(sizeof(struct information));
memcpy(tmp_info, &info, sizeof(struct information));
parse_conky_vars(&subroot, text, p, p_max_size, tmp_info);
- DBGP("evaluated '%s' to '%s'", text, p);
+ DBGP2("evaluated '%s' to '%s'", text, p);
free_text_objects(&subroot, 1);
free(tmp_info);
{
struct information *cur = &info;
char *p;
+ unsigned int i, j, k;
special_count = 0;
p = text_buffer;
generate_text_internal(p, max_user_text, global_root_object, cur);
+ if(max_text_width > 0) {
+ for(i = 0, j = 0; p[i] != 0; i++) {
+ if(p[i] == '\n') j = 0;
+ else if(j == max_text_width) {
+ k = i + strlen(p + i) + 1;
+ if(k < text_buffer_size) {
+ while(k != i) {
+ p[k] = p[k-1];
+ k--;
+ }
+ p[k] = '\n';
+ j = 0;
+ } else NORM_ERR("The end of the text_buffer is reached, increase \"text_buffer_size\"");
+ } else j++;
+ }
+ }
if (stuff_in_uppercase) {
char *tmp_p;
update_interval_old = interval;
}
-static inline int get_string_width(const char *s)
+int get_string_width(const char *s)
{
return *s ? calc_text_width(s) : 0;
}
static int text_size_updater(char *s, int special_index)
{
int w = 0;
+ int lw;
+ int contain_SECRIT_MULTILINE_CHAR = 0;
char *p;
if ((output_methods & TO_X) == 0)
special_index++;
s = p + 1;
} else if (*p == SECRIT_MULTILINE_CHAR) {
- int lw;
+ contain_SECRIT_MULTILINE_CHAR = 1;
*p = '\0';
lw = get_string_width(s);
*p = SECRIT_MULTILINE_CHAR;
}
p++;
}
- w += get_string_width(s);
+ /* Check also last substring if string contains SECRIT_MULTILINE_CHAR */
+ if (contain_SECRIT_MULTILINE_CHAR) {
+ lw = get_string_width(s);
+ w = lw > w ? lw : w;
+ } else {
+ w += get_string_width(s);
+ }
if (w > text_width) {
text_width = w;
}
{
#ifdef X11
if (output_methods & TO_X) {
- current_color = c;
- XSetForeground(display, window.gc, c);
+#ifdef USE_ARGB
+ if (have_argb_visual) {
+ current_color = c | (own_window_argb_value << 24);
+ } else {
+#endif /* USE_ARGB */
+ current_color = c;
+#ifdef USE_ARGB
+ }
+#endif /* USE_ARGB */
+ XSetForeground(display, window.gc, current_color);
}
#endif /* X11 */
#ifdef NCURSES
XftColor c2;
c.pixel = current_color;
- XQueryColor(display, DefaultColormap(display, screen), &c);
+ // query color on custom colormap
+ XQueryColor(display, window.colourmap, &c);
c2.pixel = c.pixel;
c2.color.red = c.red;
draw_stuff(); /* redraw everything in our newly sized window */
XResizeWindow(display, window.window, window.width,
window.height); /* resize window */
- set_transparent_background(window.window);
+ set_transparent_background(window.window, own_window_argb_value);
#ifdef HAVE_XDBE
/* swap buffers */
xdbe_swap_buffers();
#ifdef OWN_WINDOW
case ReparentNotify:
- /* set background to ParentRelative for all parents */
+ /* make background transparent */
if (own_window) {
- set_transparent_background(window.window);
+ set_transparent_background(window.window, own_window_argb_value);
}
break;
break;
}
#ifdef HAVE_SYS_INOTIFY_H
- if (inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
+ if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
inotify_config_wd = inotify_add_watch(inotify_fd,
current_config,
IN_MODIFY);
}
- if (inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
+ if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
int len = 0, idx = 0;
fd_set descriptors;
struct timeval time_to_wait;
len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
while (len > 0 && idx < len) {
struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
- if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
- /* current_config should be reloaded */
- NORM_ERR("'%s' modified, reloading...", current_config);
- reload_config();
+ if (ev->wd == inotify_config_wd) {
+ if (ev->mask & IN_MODIFY) {
+ /* current_config should be reloaded */
+ NORM_ERR("'%s' modified, reloading...", current_config);
+ reload_config();
+ }
if (ev->mask & IN_IGNORED) {
/* for some reason we get IN_IGNORED here
* sometimes, so we need to re-add the watch */
current_config,
IN_MODIFY);
}
+ break;
}
#ifdef HAVE_LUA
else {
idx += INOTIFY_EVENT_SIZE + ev->len;
}
}
+ } else if (disable_auto_reload && inotify_fd != -1) {
+ inotify_rm_watch(inotify_fd, inotify_config_wd);
+ close(inotify_fd);
+ inotify_fd = inotify_config_wd = 0;
}
#endif /* HAVE_SYS_INOTIFY_H */
#endif /* HAVE_LUA */
g_signal_pending = 0;
}
- clean_up(NULL, NULL);
+ clean_up(current_mail_spool, NULL);
#ifdef HAVE_SYS_INOTIFY_H
if (inotify_fd != -1) {
{
char *current_config_copy = strdup(current_config);
clean_up(NULL, NULL);
+ sleep(1); /* slight pause */
current_config = current_config_copy;
initialisation(argc_copy, argv_copy);
}
{
int i;
+ free_update_callbacks();
+
#ifdef NCURSES
if(output_methods & TO_NCURSES) {
endwin();
}
#ifdef X11
if (x_initialised == YES) {
- XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width,
- text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width,
- text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
- text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, 0);
+ if(window_created == 1) {
+ XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width,
+ text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width,
+ text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
+ text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, 0);
+ }
destroy_window();
free_fonts();
if(x11_stuff.region) {
#endif /* X11 */
- free_update_callbacks();
-
free_templates();
free_text_objects(&global_root_object, 0);
} else if (strcasecmp(s, "none") == EQUAL) {
return NONE;
}
- return TOP_LEFT;
+ return ALIGNMENT_ERROR;
}
#endif /* X11 */
window.hints = 0;
strcpy(window.class_name, PACKAGE_NAME);
sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
+#ifdef USE_ARGB
+ use_argb_visual = 0;
+ own_window_argb_value = 255;
+#endif
#endif
stippled_borders = 0;
window.border_inner_margin = 3;
XMoveWindow(display, window.window, window.x, window.y);
}
if (own_window) {
- set_transparent_background(window.window);
+ set_transparent_background(window.window, own_window_argb_value);
}
#endif
return 0;
}
+#ifdef X11
+void setalignment(int* text_alignment, unsigned int windowtype, const char* value, const char *f, int line, char setbyconffile) {
+#ifdef OWN_WINDOW
+ if (windowtype == TYPE_DOCK) {
+ NORM_ERR("alignment is disabled when own_window_type is dock");
+ } else
+#endif /*OWN_WINDOW */
+ if (value) {
+ int a = string_to_alignment(value);
+
+ if (a <= 0) {
+ if(setbyconffile == true) {
+ CONF_ERR;
+ } else NORM_ERR("'%s' is not a alignment setting", value);
+ } else {
+ *text_alignment = a;
+ }
+ } else if(setbyconffile == true) {
+ CONF_ERR;
+ }
+}
+#endif /* X11 */
+
char load_config_file(const char *f)
{
int line = 0;
}
}
CONF("alignment") {
-#ifdef OWN_WINDOW
- if (window.type == TYPE_DOCK)
- ;
- else
-#endif /*OWN_WINDOW */
- if (value) {
- int a = string_to_alignment(value);
-
- if (a <= 0) {
- CONF_ERR;
- } else {
- text_alignment = a;
- }
- } else {
- CONF_ERR;
- }
+ setalignment(&text_alignment, window.type, value, f, line, true);
}
CONF("background") {
fork_to_background = string_to_bool(value);
CONF("times_in_seconds") {
set_times_in_seconds(string_to_bool(value));
}
+ CONF("max_text_width") {
+ max_text_width = atoi(value);
+ }
CONF("out_to_console") {
if(string_to_bool(value)) {
output_methods |= TO_STDOUT;
CONF("extra_newline") {
extra_newline = string_to_bool(value);
}
+ CONF("disable_auto_reload") {
+ disable_auto_reload = string_to_bool(value);
+ }
CONF("out_to_stderr") {
if(string_to_bool(value))
output_methods |= TO_STDERR;
CONF_ERR;
}
}
+#ifdef USE_ARGB
+ CONF("own_window_argb_visual") {
+ use_argb_visual = string_to_bool(value);
+ }
+ CONF("own_window_argb_value") {
+ own_window_argb_value = strtol(value, 0, 0);
+ if (own_window_argb_value > 255 || own_window_argb_value < 0) {
+ CONF_ERR2("own_window_argb_value must be <= 255 and >= 0");
+ }
+ }
+#endif /* USE_ARGB */
#endif
CONF("stippled_borders") {
if (value) {
set_first_font(optarg);
break;
case 'a':
- text_alignment = string_to_alignment(optarg);
+ setalignment(&text_alignment, window.type, optarg, NULL, 0, false);
break;
#ifdef OWN_WINDOW
break;
#endif /* X11 */
case 'p':
- startup_pause = atoi(optarg);
- sleep(startup_pause);
+ if (first_pass) {
+ startup_pause = atoi(optarg);
+ sleep(startup_pause);
+ }
break;
case '?':
}
global_text = NULL;
/* fork */
- if (fork_to_background) {
+ if (fork_to_background && first_pass) {
int pid = fork();
switch (pid) {
initialisation(argc, argv);
+ first_pass = 0; /* don't ever call fork() again */
+
main_loop();
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)