2009-07-28 21:44:22 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2005-07-20 00:30:40 +00:00
|
|
|
*
|
2007-08-10 19:53:44 +00:00
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
2009-03-30 04:55:30 +00:00
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-05 01:06:17 +00:00
|
|
|
*
|
2009-07-27 20:47:19 +00:00
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "config.h"
|
2008-12-15 17:31:23 +00:00
|
|
|
#include "text_object.h"
|
2005-07-20 00:30:40 +00:00
|
|
|
#include "conky.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "common.h"
|
2009-08-06 06:54:40 +00:00
|
|
|
#include "core.h"
|
2008-04-17 20:40:53 +00:00
|
|
|
#include <stdarg.h>
|
2008-04-17 20:46:29 +00:00
|
|
|
#include <math.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#if HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/time.h>
|
2008-12-23 03:59:42 +00:00
|
|
|
#include <sys/param.h>
|
2009-05-19 23:14:34 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
#include <sys/inotify.h>
|
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "x11.h"
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <X11/Xutil.h>
|
2006-11-20 20:17:46 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2006-05-24 06:34:37 +00:00
|
|
|
#include <X11/extensions/Xdamage.h>
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2009-08-07 07:21:56 +00:00
|
|
|
#ifdef IMLIB2
|
|
|
|
#include "imlib2.h"
|
|
|
|
#endif /* IMLIB2 */
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2006-05-12 12:41:18 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
2007-09-28 20:16:16 +00:00
|
|
|
#include <fcntl.h>
|
2008-01-06 01:35:14 +00:00
|
|
|
#include <getopt.h>
|
2009-08-03 17:58:21 +00:00
|
|
|
#ifdef XOAP
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#endif /* XOAP */
|
2006-03-22 19:35:58 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* local headers */
|
2009-08-06 06:54:40 +00:00
|
|
|
#include "obj_create.h"
|
|
|
|
#include "obj_display.h"
|
|
|
|
#include "obj_destroy.h"
|
2008-12-20 01:31:00 +00:00
|
|
|
#include "algebra.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "build.h"
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "colours.h"
|
2009-08-07 07:21:56 +00:00
|
|
|
#include "diskio.h"
|
2009-03-17 17:36:46 +00:00
|
|
|
#ifdef X11
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "fonts.h"
|
2009-03-17 17:36:46 +00:00
|
|
|
#endif
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "fs.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "mixer.h"
|
|
|
|
#include "mail.h"
|
|
|
|
#include "mboxscan.h"
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "specials.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "temphelper.h"
|
2009-01-05 12:11:13 +00:00
|
|
|
#include "tailhead.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "top.h"
|
|
|
|
|
|
|
|
/* check for OS and include appropriate headers */
|
|
|
|
#if defined(__linux__)
|
|
|
|
#include "linux.h"
|
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
|
|
#include "freebsd.h"
|
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
#include "openbsd.h"
|
|
|
|
#endif
|
|
|
|
|
2009-05-29 15:12:12 +00:00
|
|
|
#if defined(__FreeBSD_kernel__)
|
|
|
|
#include <bsd/bsd.h>
|
|
|
|
#endif
|
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
|
|
|
|
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
|
|
|
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
|
|
|
|
int apm_getinfo(int fd, apm_info_t aip);
|
|
|
|
char *get_apm_adapter(void);
|
|
|
|
char *get_apm_battery_life(void);
|
|
|
|
char *get_apm_battery_time(void);
|
|
|
|
#endif
|
|
|
|
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
#include "defconfig.h"
|
2008-12-14 13:36:44 +00:00
|
|
|
#include "conf_cookie.h"
|
|
|
|
#endif
|
2008-12-12 14:33:25 +00:00
|
|
|
|
2006-12-11 19:04:58 +00:00
|
|
|
#ifndef S_ISSOCK
|
|
|
|
#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
|
|
|
|
#endif
|
|
|
|
|
2009-08-07 07:21:56 +00:00
|
|
|
#define MAIL_FILE "$MAIL"
|
2005-07-20 00:30:40 +00:00
|
|
|
#define MAX_IF_BLOCK_DEPTH 5
|
|
|
|
|
2008-09-26 21:09:48 +00:00
|
|
|
//#define SIGNAL_BLOCKING
|
|
|
|
#undef SIGNAL_BLOCKING
|
2005-11-24 02:18:42 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* debugging level, used by logging.h */
|
2008-11-30 20:53:20 +00:00
|
|
|
int global_debug_level = 0;
|
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
static volatile int g_signal_pending;
|
|
|
|
|
2009-07-17 16:01:41 +00:00
|
|
|
int argc_copy;
|
|
|
|
char** argv_copy;
|
2008-12-15 21:40:24 +00:00
|
|
|
|
|
|
|
/* prototypes for internally used functions */
|
|
|
|
static void signal_handler(int);
|
2008-03-29 11:35:02 +00:00
|
|
|
static void print_version(void) __attribute__((noreturn));
|
2009-08-07 07:21:56 +00:00
|
|
|
static void reload_config(void);
|
2008-03-29 11:35:02 +00:00
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void print_version(void)
|
2006-08-12 06:10:18 +00:00
|
|
|
{
|
2008-07-12 10:25:05 +00:00
|
|
|
printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
|
2006-08-12 06:36:58 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
printf("\nCompiled in features:\n\n"
|
2009-07-08 08:09:06 +00:00
|
|
|
"System config file: "SYSTEM_CONFIG_FILE"\n"
|
|
|
|
"Package library path: "PACKAGE_LIBDIR"\n\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
" X11:\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# ifdef HAVE_XDAMAGE
|
2008-02-20 20:30:45 +00:00
|
|
|
" * Xdamage extension\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# endif /* HAVE_XDAMAGE */
|
|
|
|
# ifdef HAVE_XDBE
|
2009-03-18 06:29:01 +00:00
|
|
|
" * XDBE (double buffer extension)\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# endif /* HAVE_XDBE */
|
2006-11-07 01:19:32 +00:00
|
|
|
# ifdef XFT
|
2009-03-18 06:29:01 +00:00
|
|
|
" * Xft\n"
|
2006-11-07 01:19:32 +00:00
|
|
|
# endif /* XFT */
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
"\n Music detection:\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#ifdef AUDACIOUS
|
2009-03-18 06:29:01 +00:00
|
|
|
" * Audacious\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* AUDACIOUS */
|
|
|
|
#ifdef BMPX
|
2009-03-18 06:29:01 +00:00
|
|
|
" * BMPx\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* BMPX */
|
|
|
|
#ifdef MPD
|
2009-03-18 06:29:01 +00:00
|
|
|
" * MPD\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* MPD */
|
2008-09-24 06:59:45 +00:00
|
|
|
#ifdef MOC
|
2009-03-18 06:29:01 +00:00
|
|
|
" * MOC\n"
|
2008-09-24 06:59:45 +00:00
|
|
|
#endif /* MOC */
|
2006-11-05 00:23:18 +00:00
|
|
|
#ifdef XMMS2
|
2009-03-18 06:29:01 +00:00
|
|
|
" * XMMS2\n"
|
2006-11-05 00:23:18 +00:00
|
|
|
#endif /* XMMS2 */
|
2009-03-18 06:29:01 +00:00
|
|
|
"\n General:\n"
|
2009-05-24 03:17:35 +00:00
|
|
|
#ifdef HAVE_OPENMP
|
|
|
|
" * OpenMP\n"
|
|
|
|
#endif /* HAVE_OPENMP */
|
2008-07-01 11:13:40 +00:00
|
|
|
#ifdef MATH
|
|
|
|
" * math\n"
|
|
|
|
#endif /* Math */
|
2006-11-05 00:23:18 +00:00
|
|
|
#ifdef HDDTEMP
|
2008-02-20 20:30:45 +00:00
|
|
|
" * hddtemp\n"
|
2006-11-05 00:23:18 +00:00
|
|
|
#endif /* HDDTEMP */
|
2006-08-12 06:36:58 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
" * portmon\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* TCP_PORT_MONITOR */
|
2009-07-20 05:43:36 +00:00
|
|
|
#ifdef HAVE_CURL
|
|
|
|
" * Curl\n"
|
|
|
|
#endif /* HAVE_CURL */
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
2009-03-18 06:29:01 +00:00
|
|
|
" * RSS\n"
|
2007-06-02 08:17:33 +00:00
|
|
|
#endif /* RSS */
|
2009-07-06 22:20:12 +00:00
|
|
|
#ifdef WEATHER
|
2009-07-20 19:17:44 +00:00
|
|
|
" * Weather (METAR)\n"
|
2009-07-19 16:14:22 +00:00
|
|
|
#ifdef XOAP
|
|
|
|
" * Weather (XOAP)\n"
|
|
|
|
#endif /* XOAP */
|
2009-07-06 22:20:12 +00:00
|
|
|
#endif /* WEATHER */
|
2007-08-07 22:05:06 +00:00
|
|
|
#ifdef HAVE_IWLIB
|
2008-02-20 20:30:45 +00:00
|
|
|
" * wireless\n"
|
2008-03-18 00:23:16 +00:00
|
|
|
#endif /* HAVE_IWLIB */
|
2009-01-03 23:25:15 +00:00
|
|
|
#ifdef IBM
|
2009-03-18 06:29:01 +00:00
|
|
|
" * support for IBM/Lenovo notebooks\n"
|
2009-01-03 23:25:15 +00:00
|
|
|
#endif /* IBM */
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
2009-03-18 06:29:01 +00:00
|
|
|
" * nvidia\n"
|
2009-03-19 04:02:25 +00:00
|
|
|
#endif /* NVIDIA */
|
2009-03-18 06:29:01 +00:00
|
|
|
#ifdef EVE
|
|
|
|
" * eve-online\n"
|
|
|
|
#endif /* EVE */
|
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
" * config-output\n"
|
|
|
|
#endif /* CONFIG_OUTPUT */
|
2009-03-19 04:02:25 +00:00
|
|
|
#ifdef IMLIB2
|
2009-06-06 08:32:51 +00:00
|
|
|
" * Imlib2\n"
|
2009-03-19 04:02:25 +00:00
|
|
|
#endif /* IMLIB2 */
|
2009-04-28 16:56:49 +00:00
|
|
|
#ifdef MIXER_IS_ALSA
|
|
|
|
" * ALSA mixer support\n"
|
|
|
|
#endif /* MIXER_IS_ALSA */
|
2009-05-10 18:58:06 +00:00
|
|
|
#ifdef APCUPSD
|
2009-06-12 17:08:44 +00:00
|
|
|
" * apcupsd\n"
|
2009-05-10 18:58:06 +00:00
|
|
|
#endif /* APCUPSD */
|
2009-06-12 17:08:44 +00:00
|
|
|
#ifdef IOSTATS
|
|
|
|
" * iostats\n"
|
|
|
|
#endif /* IOSTATS */
|
2009-07-08 08:09:06 +00:00
|
|
|
#ifdef HAVE_LUA
|
|
|
|
" * Lua\n"
|
|
|
|
"\n Lua bindings:\n"
|
|
|
|
#ifdef HAVE_LUA_CAIRO
|
|
|
|
" * Cairo\n"
|
|
|
|
#endif /* HAVE_LUA_CAIRO */
|
|
|
|
#ifdef HAVE_LUA_IMLIB2
|
|
|
|
" * Imlib2\n"
|
|
|
|
#endif /* IMLIB2 */
|
|
|
|
#endif /* HAVE_LUA */
|
2008-02-20 20:30:45 +00:00
|
|
|
);
|
2006-08-12 06:36:58 +00:00
|
|
|
|
2009-07-26 23:29:57 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2006-08-12 06:10:18 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
int inotify_fd;
|
2009-05-20 03:34:43 +00:00
|
|
|
#endif
|
2008-04-13 04:10:35 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
static void main_loop(conky_context *ctx)
|
2009-08-05 22:46:51 +00:00
|
|
|
{
|
2009-08-06 06:54:40 +00:00
|
|
|
int terminate = 0;
|
|
|
|
#ifdef SIGNAL_BLOCKING
|
|
|
|
sigset_t newmask, oldmask;
|
2005-08-06 00:26:14 +00:00
|
|
|
#endif
|
2009-08-06 06:54:40 +00:00
|
|
|
double t;
|
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
int inotify_config_wd = -1;
|
|
|
|
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
|
|
|
|
#define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
|
|
|
|
char inotify_buff[INOTIFY_BUF_LEN];
|
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-05-13 19:51:26 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
|
|
|
sigemptyset(&newmask);
|
|
|
|
sigaddset(&newmask, SIGINT);
|
|
|
|
sigaddset(&newmask, SIGTERM);
|
|
|
|
sigaddset(&newmask, SIGUSR1);
|
2007-03-01 01:43:43 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->next_update_time = get_time();
|
|
|
|
while (terminate == 0 && (ctx->total_run_times == 0 || ctx->info.looped < ctx->total_run_times)) {
|
|
|
|
if (ctx->update_interval_bat != NOBATTERY && ctx->update_interval_bat != ctx->update_interval_old) {
|
|
|
|
char buf[ctx->max_user_text];
|
2007-02-12 01:03:10 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
get_battery_short_status(buf, ctx->max_user_text, "BAT0");
|
|
|
|
if(buf[0] == 'D') {
|
|
|
|
ctx->update_interval = ctx->update_interval_bat;
|
|
|
|
} else {
|
|
|
|
ctx->update_interval = ctx->update_interval_old;
|
2007-04-06 06:11:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->info.looped++;
|
2009-07-21 02:11:33 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
|
|
|
/* block signals. we will inspect for pending signals later */
|
|
|
|
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
|
|
|
|
CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
|
2005-07-25 01:13:26 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef X11
|
|
|
|
if (ctx->output_methods & TO_X) {
|
|
|
|
XFlush(display);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* wait for X event or timeout */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
if (!XPending(display)) {
|
|
|
|
fd_set fdsr;
|
|
|
|
struct timeval tv;
|
|
|
|
int s;
|
|
|
|
t = ctx->next_update_time - get_time();
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
if (t < 0) {
|
|
|
|
t = 0;
|
|
|
|
} else if (t > ctx->update_interval) {
|
|
|
|
t = ctx->update_interval;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
tv.tv_sec = (long) t;
|
|
|
|
tv.tv_usec = (long) (t * 1000000) % 1000000;
|
|
|
|
FD_ZERO(&fdsr);
|
|
|
|
FD_SET(ConnectionNumber(display), &fdsr);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
|
|
|
|
if (s == -1) {
|
|
|
|
if (errno != EINTR) {
|
|
|
|
NORM_ERR("can't select(): %s", strerror(errno));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* timeout */
|
|
|
|
if (s == 0) {
|
|
|
|
update_text(ctx);
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-08-05 22:46:51 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->need_to_update) {
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
int wx = ctx->window.x, wy = ctx->window.y;
|
|
|
|
#endif
|
2008-11-29 01:34:54 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->need_to_update = 0;
|
|
|
|
ctx->selected_font = 0;
|
|
|
|
update_text_area(ctx);
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
if (ctx->own_window) {
|
|
|
|
int changed = 0;
|
2008-11-29 01:34:54 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* resize ctx->window if it isn't right size */
|
|
|
|
if (!ctx->fixed_size
|
|
|
|
&& (ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2 != ctx->window.width
|
|
|
|
|| ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2 != ctx->window.height)) {
|
|
|
|
ctx->window.width = ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2;
|
|
|
|
ctx->window.height = ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2;
|
|
|
|
draw_stuff(ctx); /* redraw everything in our newly sized ctx->window */
|
|
|
|
XResizeWindow(display, ctx->window.window, ctx->window.width,
|
|
|
|
ctx->window.height); /* resize ctx->window */
|
|
|
|
set_transparent_background(ctx->window.window);
|
|
|
|
#ifdef HAVE_XDBE
|
|
|
|
/* swap buffers */
|
|
|
|
xdbe_swap_buffers();
|
|
|
|
#endif
|
2008-11-29 01:34:54 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
changed++;
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
/* update lua ctx->window globals */
|
|
|
|
llua_update_window_table(ctx->text_start_x, ctx->text_start_y, ctx->text_width, ctx->text_height);
|
|
|
|
#endif /* HAVE_LUA */
|
|
|
|
}
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* move ctx->window if it isn't in right position */
|
|
|
|
if (!ctx->fixed_pos && (ctx->window.x != wx || ctx->window.y != wy)) {
|
|
|
|
XMoveWindow(display, ctx->window.window, ctx->window.x, ctx->window.y);
|
|
|
|
changed++;
|
|
|
|
}
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* update struts */
|
|
|
|
if (changed && ctx->window.type == TYPE_PANEL) {
|
|
|
|
int sidenum = -1;
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
fprintf(stderr, PACKAGE_NAME": defining struts\n");
|
|
|
|
fflush(stderr);
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
switch (ctx->text_alignment) {
|
|
|
|
case TOP_LEFT:
|
|
|
|
case TOP_RIGHT:
|
|
|
|
case TOP_MIDDLE:
|
|
|
|
{
|
|
|
|
sidenum = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BOTTOM_LEFT:
|
|
|
|
case BOTTOM_RIGHT:
|
|
|
|
case BOTTOM_MIDDLE:
|
|
|
|
{
|
|
|
|
sidenum = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIDDLE_LEFT:
|
|
|
|
{
|
|
|
|
sidenum = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIDDLE_RIGHT:
|
|
|
|
{
|
|
|
|
sidenum = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
set_struts(sidenum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
clear_text(ctx, 1);
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef HAVE_XDBE
|
|
|
|
if (use_xdbe) {
|
|
|
|
XRectangle r;
|
2008-11-29 01:34:54 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
r.x = ctx->text_start_x - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width;
|
|
|
|
r.y = ctx->text_start_y - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width;
|
|
|
|
r.width = ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2;
|
|
|
|
r.height = ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2;
|
|
|
|
XUnionRectWithRegion(&r, ctx->window.region, ctx->window.region);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2009-05-13 00:05:51 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* handle X events */
|
|
|
|
while (XPending(display)) {
|
|
|
|
XEvent ev;
|
2009-05-13 00:05:51 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
XNextEvent(display, &ev);
|
|
|
|
switch (ev.type) {
|
|
|
|
case Expose:
|
|
|
|
{
|
|
|
|
XRectangle r;
|
|
|
|
r.x = ev.xexpose.x;
|
|
|
|
r.y = ev.xexpose.y;
|
|
|
|
r.width = ev.xexpose.width;
|
|
|
|
r.height = ev.xexpose.height;
|
|
|
|
XUnionRectWithRegion(&r, ctx->window.region, ctx->window.region);
|
|
|
|
break;
|
|
|
|
}
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
case PropertyNotify:
|
|
|
|
{
|
|
|
|
if ( ev.xproperty.state == PropertyNewValue ) {
|
|
|
|
get_x11_desktop_info( ev.xproperty.display, ev.xproperty.atom );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
case ReparentNotify:
|
|
|
|
/* set background to ParentRelative for all parents */
|
|
|
|
if (ctx->own_window) {
|
|
|
|
set_transparent_background(ctx->window.window);
|
|
|
|
}
|
|
|
|
break;
|
2006-05-14 07:05:05 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
case ConfigureNotify:
|
|
|
|
if (ctx->own_window) {
|
|
|
|
/* if ctx->window size isn't what expected, set fixed size */
|
|
|
|
if (ev.xconfigure.width != ctx->window.width
|
|
|
|
|| ev.xconfigure.height != ctx->window.height) {
|
|
|
|
if (ctx->window.width != 0 && ctx->window.height != 0) {
|
|
|
|
ctx->fixed_size = 1;
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* clear old stuff before screwing up
|
|
|
|
* size and pos */
|
|
|
|
clear_text(ctx, 1);
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
{
|
|
|
|
XWindowAttributes attrs;
|
|
|
|
if (XGetWindowAttributes(display,
|
|
|
|
ctx->window.window, &attrs)) {
|
|
|
|
ctx->window.width = attrs.width;
|
|
|
|
ctx->window.height = attrs.height;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->text_width = ctx->window.width - ctx->window.border_inner_margin * 2 - ctx->window.border_outer_margin * 2 - ctx->window.border_width * 2;
|
|
|
|
ctx->text_height = ctx->window.height - ctx->window.border_inner_margin * 2 - ctx->window.border_outer_margin * 2 - ctx->window.border_width * 2;
|
|
|
|
if (ctx->text_width > ctx->maximum_width
|
|
|
|
&& ctx->maximum_width > 0) {
|
|
|
|
ctx->text_width = ctx->maximum_width;
|
|
|
|
}
|
|
|
|
}
|
2008-12-16 04:17:56 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* if position isn't what expected, set fixed pos
|
|
|
|
* total_updates avoids setting ctx->fixed_pos when ctx->window
|
|
|
|
* is set to weird locations when started */
|
|
|
|
/* // this is broken
|
|
|
|
if (total_updates >= 2 && !ctx->fixed_pos
|
|
|
|
&& (ctx->window.x != ev.xconfigure.x
|
|
|
|
|| ctx->window.y != ev.xconfigure.y)
|
|
|
|
&& (ev.xconfigure.x != 0
|
|
|
|
|| ev.xconfigure.y != 0)) {
|
|
|
|
ctx->fixed_pos = 1;
|
|
|
|
} */
|
|
|
|
}
|
|
|
|
break;
|
2008-12-16 04:17:56 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
case ButtonPress:
|
|
|
|
if (ctx->own_window) {
|
|
|
|
/* if an ordinary ctx->window with decorations */
|
|
|
|
if ((ctx->window.type == TYPE_NORMAL &&
|
|
|
|
(!TEST_HINT(ctx->window.hints,
|
|
|
|
HINT_UNDECORATED))) ||
|
|
|
|
ctx->window.type == TYPE_DESKTOP) {
|
|
|
|
/* allow conky to hold input focus. */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* forward the click to the desktop ctx->window */
|
|
|
|
XUngrabPointer(display, ev.xbutton.time);
|
|
|
|
ev.xbutton.window = ctx->window.desktop;
|
|
|
|
ev.xbutton.x = ev.xbutton.x_root;
|
|
|
|
ev.xbutton.y = ev.xbutton.y_root;
|
|
|
|
XSendEvent(display, ev.xbutton.window, False,
|
|
|
|
ButtonPressMask, &ev);
|
|
|
|
XSetInputFocus(display, ev.xbutton.window,
|
|
|
|
RevertToParent, ev.xbutton.time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-12-16 04:17:56 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
case ButtonRelease:
|
|
|
|
if (ctx->own_window) {
|
|
|
|
/* if an ordinary ctx->window with decorations */
|
|
|
|
if ((ctx->window.type == TYPE_NORMAL)
|
|
|
|
&& (!TEST_HINT(ctx->window.hints,
|
|
|
|
HINT_UNDECORATED))) {
|
|
|
|
/* allow conky to hold input focus. */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* forward the release to the desktop ctx->window */
|
|
|
|
ev.xbutton.window = ctx->window.desktop;
|
|
|
|
ev.xbutton.x = ev.xbutton.x_root;
|
|
|
|
ev.xbutton.y = ev.xbutton.y_root;
|
|
|
|
XSendEvent(display, ev.xbutton.window, False,
|
|
|
|
ButtonReleaseMask, &ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2005-11-11 03:28:24 +00:00
|
|
|
#endif
|
2008-12-07 19:08:29 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
default:
|
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
if (ev.type == ctx->window.event_base + XDamageNotify) {
|
|
|
|
XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
|
2008-12-07 19:08:29 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
XFixesSetRegion(display, ctx->window.part, &dev->area, 1);
|
|
|
|
XFixesUnionRegion(display, ctx->window.region2, ctx->window.region2, ctx->window.part);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_XDAMAGE */
|
|
|
|
break;
|
2009-05-15 18:08:51 +00:00
|
|
|
}
|
2009-08-01 20:30:14 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
XDamageSubtract(display, ctx->window.damage, ctx->window.region2, None);
|
|
|
|
XFixesSetRegion(display, ctx->window.region2, 0, 0);
|
|
|
|
#endif /* HAVE_XDAMAGE */
|
2009-04-01 17:06:31 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* XDBE doesn't seem to provide a way to clear the back buffer
|
|
|
|
* without interfering with the front buffer, other than passing
|
|
|
|
* XdbeBackground to XdbeSwapBuffers. That means that if we're
|
|
|
|
* using XDBE, we need to redraw the text even if it wasn't part of
|
|
|
|
* the exposed area. OTOH, if we're not going to call draw_stuff at
|
|
|
|
* all, then no swap happens and we can safely do nothing. */
|
2009-04-01 17:06:31 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
if (!XEmptyRegion(ctx->window.region)) {
|
|
|
|
#ifdef HAVE_XDBE
|
|
|
|
if (use_xdbe) {
|
|
|
|
XRectangle r;
|
2009-04-01 17:06:31 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
r.x = ctx->text_start_x - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width;
|
|
|
|
r.y = ctx->text_start_y - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width;
|
|
|
|
r.width = ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2;
|
|
|
|
r.height = ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2;
|
|
|
|
XUnionRectWithRegion(&r, ctx->window.region, ctx->window.region);
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif
|
|
|
|
XSetRegion(display, ctx->window.gc, ctx->window.region);
|
|
|
|
#ifdef XFT
|
|
|
|
if (use_xft) {
|
|
|
|
XftDrawSetClip(ctx->window.xftdraw, ctx->window.region);
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif
|
|
|
|
draw_stuff(ctx);
|
|
|
|
XDestroyRegion(ctx->window.region);
|
|
|
|
ctx->window.region = XCreateRegion();
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
} else {
|
|
|
|
#endif /* X11 */
|
|
|
|
t = (ctx->next_update_time - get_time()) * 1000000;
|
|
|
|
if(t > 0) usleep((useconds_t)t);
|
|
|
|
update_text(ctx);
|
|
|
|
draw_stuff(ctx);
|
|
|
|
#ifdef NCURSES
|
|
|
|
if(ctx->output_methods & TO_NCURSES) {
|
|
|
|
refresh();
|
|
|
|
clear();
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef X11
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
|
|
|
#ifdef SIGNAL_BLOCKING
|
|
|
|
/* unblock signals of interest and let handler fly */
|
|
|
|
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
|
|
|
|
CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (g_signal_pending) {
|
|
|
|
case SIGHUP:
|
|
|
|
case SIGUSR1:
|
|
|
|
NORM_ERR("received SIGHUP or SIGUSR1. reloading the config file.");
|
2009-08-07 07:21:56 +00:00
|
|
|
reload_config();
|
2009-08-06 06:54:40 +00:00
|
|
|
break;
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
NORM_ERR("received SIGINT or SIGTERM to terminate. bye!");
|
|
|
|
terminate = 1;
|
|
|
|
#ifdef X11
|
|
|
|
if (ctx->output_methods & TO_X) {
|
|
|
|
XDestroyRegion(ctx->window.region);
|
|
|
|
ctx->window.region = NULL;
|
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
XDamageDestroy(display, ctx->window.damage);
|
|
|
|
XFixesDestroyRegion(display, ctx->window.region2);
|
|
|
|
XFixesDestroyRegion(display, ctx->window.part);
|
|
|
|
#endif /* HAVE_XDAMAGE */
|
|
|
|
if (ctx->disp) {
|
|
|
|
free(ctx->disp);
|
|
|
|
}
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
if(ctx->overwrite_file) {
|
|
|
|
free(ctx->overwrite_file);
|
|
|
|
ctx->overwrite_file = 0;
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
if(ctx->append_file) {
|
|
|
|
free(ctx->append_file);
|
|
|
|
ctx->append_file = 0;
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Reaching here means someone set a signal
|
|
|
|
* (SIGXXXX, signal_handler), but didn't write any code
|
|
|
|
* to deal with it.
|
|
|
|
* If you don't want to handle a signal, don't set a handler on
|
|
|
|
* it in the first place. */
|
|
|
|
if (g_signal_pending) {
|
|
|
|
NORM_ERR("ignoring signal (%d)", g_signal_pending);
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
break;
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
if (inotify_fd != -1 && inotify_config_wd == -1 && ctx->current_config != 0) {
|
|
|
|
inotify_config_wd = inotify_add_watch(inotify_fd,
|
|
|
|
ctx->current_config,
|
|
|
|
IN_MODIFY);
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
if (inotify_fd != -1 && inotify_config_wd != -1 && ctx->current_config != 0) {
|
|
|
|
int len = 0, idx = 0;
|
|
|
|
fd_set descriptors;
|
|
|
|
struct timeval time_to_wait;
|
|
|
|
|
|
|
|
FD_ZERO(&descriptors);
|
|
|
|
FD_SET(inotify_fd, &descriptors);
|
|
|
|
|
|
|
|
time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
|
|
|
|
|
|
|
|
select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
|
|
|
|
if (FD_ISSET(inotify_fd, &descriptors)) {
|
|
|
|
/* process inotify events */
|
|
|
|
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)) {
|
|
|
|
/* ctx->current_config should be reloaded */
|
|
|
|
NORM_ERR("'%s' modified, reloading...", ctx->current_config);
|
2009-08-07 07:21:56 +00:00
|
|
|
reload_config();
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ev->mask & IN_IGNORED) {
|
|
|
|
/* for some reason we get IN_IGNORED here
|
|
|
|
* sometimes, so we need to re-add the watch */
|
|
|
|
inotify_config_wd = inotify_add_watch(inotify_fd,
|
|
|
|
ctx->current_config,
|
|
|
|
IN_MODIFY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
else {
|
|
|
|
llua_inotify_query(ev->wd, ev->mask);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LUA */
|
|
|
|
idx += INOTIFY_EVENT_SIZE + ev->len;
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
2009-04-01 17:06:31 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef HAVE_LUA
|
|
|
|
llua_update_info(ctx, ctx->update_interval);
|
|
|
|
#endif /* HAVE_LUA */
|
|
|
|
g_signal_pending = 0;
|
|
|
|
}
|
2009-08-07 07:21:56 +00:00
|
|
|
clean_up(NULL, NULL);
|
2009-04-01 17:06:31 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
if (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 */
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
|
|
|
|
2008-06-19 19:59:30 +00:00
|
|
|
static void print_help(const char *prog_name) {
|
|
|
|
printf("Usage: %s [OPTION]...\n"
|
2008-07-12 10:25:05 +00:00
|
|
|
PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
|
2009-08-06 06:54:40 +00:00
|
|
|
"ctx->window. Command line options will override configurations defined in config\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
"file.\n"
|
|
|
|
" -v, --version version\n"
|
|
|
|
" -q, --quiet quiet mode\n"
|
2009-06-07 00:10:20 +00:00
|
|
|
" -D, --debug increase debugging output, ie. -DD for more debugging\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
" -c, --config=FILE config file to load\n"
|
2009-02-22 17:55:39 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
" -C, --print-config print the builtin default config to stdout\n"
|
|
|
|
" e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
|
|
|
|
#endif
|
2008-06-19 19:59:30 +00:00
|
|
|
" -d, --daemonize daemonize, fork to background\n"
|
|
|
|
" -h, --help help\n"
|
|
|
|
#ifdef X11
|
|
|
|
" -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
|
|
|
|
" -f, --font=FONT font to use\n"
|
2009-05-10 05:30:42 +00:00
|
|
|
" -X, --display=DISPLAY X11 display to use\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2009-08-06 06:54:40 +00:00
|
|
|
" -o, --own-ctx->window create own ctx->window to draw\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XDBE
|
|
|
|
" -b, --double-buffer double buffer (prevents flickering)\n"
|
|
|
|
#endif
|
2009-08-06 06:54:40 +00:00
|
|
|
" -w, --ctx->window-id=WIN_ID ctx->window id to draw\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
" -x X x position\n"
|
|
|
|
" -y Y y position\n"
|
|
|
|
#endif /* X11 */
|
|
|
|
" -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
|
|
|
|
" -u, --interval=SECS update interval\n"
|
2008-07-12 10:25:05 +00:00
|
|
|
" -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
|
2008-06-19 19:59:30 +00:00
|
|
|
prog_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-02-20 10:01:13 +00:00
|
|
|
/* : means that character before that takes an argument */
|
2008-11-30 20:53:20 +00:00
|
|
|
static const char *getopt_string = "vVqdDt:u:i:hc:"
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-04-01 17:06:31 +00:00
|
|
|
"x:y:w:a:f:X:"
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
"o"
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2008-02-20 20:30:45 +00:00
|
|
|
"b"
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-22 17:55:39 +00:00
|
|
|
#endif /* X11 */
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
"C"
|
|
|
|
#endif
|
2008-01-06 01:35:14 +00:00
|
|
|
;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static const struct option longopts[] = {
|
|
|
|
{ "help", 0, NULL, 'h' },
|
|
|
|
{ "version", 0, NULL, 'V' },
|
2008-11-30 20:53:20 +00:00
|
|
|
{ "debug", 0, NULL, 'D' },
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "config", 1, NULL, 'c' },
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
{ "print-config", 0, NULL, 'C' },
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "daemonize", 0, NULL, 'd' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "alignment", 1, NULL, 'a' },
|
|
|
|
{ "font", 1, NULL, 'f' },
|
2009-04-01 17:06:31 +00:00
|
|
|
{ "display", 1, NULL, 'X' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2009-08-06 06:54:40 +00:00
|
|
|
{ "own-ctx->window", 0, NULL, 'o' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XDBE
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "double-buffer", 0, NULL, 'b' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#endif
|
2009-08-06 06:54:40 +00:00
|
|
|
{ "ctx->window-id", 1, NULL, 'w' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "text", 1, NULL, 't' },
|
|
|
|
{ "interval", 0, NULL, 'u' },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
void initialisation(conky_context *ctx, int argc, char **argv)
|
|
|
|
{
|
2005-11-23 19:05:23 +00:00
|
|
|
struct sigaction act, oact;
|
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
set_default_configurations(ctx);
|
|
|
|
load_config_file(ctx, ctx->current_config);
|
|
|
|
currentconffile = conftree_add(currentconffile, ctx->current_config);
|
2007-10-23 21:52:11 +00:00
|
|
|
|
2006-11-22 21:53:54 +00:00
|
|
|
/* init specials array */
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("failed to create specials array");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-11-22 21:53:54 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef MAIL_FILE
|
2005-07-30 22:59:01 +00:00
|
|
|
if (current_mail_spool == NULL) {
|
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
variable_substitute(MAIL_FILE, buf, 256);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (buf[0] != '\0') {
|
2008-04-02 18:44:49 +00:00
|
|
|
current_mail_spool = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
/* handle other command line arguments */
|
|
|
|
|
2008-02-24 16:35:18 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
|
2008-02-20 10:01:00 +00:00
|
|
|
|| defined(__NetBSD__)
|
2005-08-24 12:05:47 +00:00
|
|
|
optind = optreset = 1;
|
|
|
|
#else
|
2005-07-30 22:59:01 +00:00
|
|
|
optind = 0;
|
2005-08-24 12:05:47 +00:00
|
|
|
#endif
|
2006-03-22 19:27:31 +00:00
|
|
|
|
2007-12-31 00:00:35 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
|
|
|
|
"kvm_open")) == NULL) {
|
2009-07-16 18:28:23 +00:00
|
|
|
CRIT_ERR(NULL, NULL, "cannot read kvm");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-03-22 19:27:31 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
while (1) {
|
2008-01-06 01:35:14 +00:00
|
|
|
int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (c == -1) {
|
2005-07-30 22:59:01 +00:00
|
|
|
break;
|
2008-01-06 01:35:14 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
switch (c) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'd':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->fork_to_background = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2008-11-30 20:53:20 +00:00
|
|
|
case 'D':
|
|
|
|
global_debug_level++;
|
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
|
|
|
case 'f':
|
2009-08-07 07:21:56 +00:00
|
|
|
set_first_font(optarg);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
case 'a':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->text_alignment = string_to_alignment(optarg);
|
2005-08-08 01:18:52 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'o':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->own_window = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'b':
|
2005-08-26 02:16:35 +00:00
|
|
|
use_xdbe = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
case 't':
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->global_text) {
|
|
|
|
free(ctx->global_text);
|
|
|
|
ctx->global_text = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->global_text = strndup(optarg, ctx->max_user_text);
|
|
|
|
convert_escapes(ctx->global_text);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'u':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->update_interval = strtod(optarg, 0);
|
|
|
|
ctx->update_interval_old = ctx->update_interval;
|
|
|
|
if (ctx->info.music_player_interval == 0) {
|
|
|
|
// default to ctx->update_interval
|
|
|
|
ctx->info.music_player_interval = ctx->update_interval;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'i':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->total_run_times = strtod(optarg, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'x':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->gap_x = atoi(optarg);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'y':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->gap_y = atoi(optarg);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-30 22:59:01 +00:00
|
|
|
/* load font */
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->output_methods & TO_X) {
|
|
|
|
load_config_file_x11(ctx, ctx->current_config);
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
/* generate text and get initial size */
|
2009-08-06 06:54:40 +00:00
|
|
|
extract_variable_text(ctx, ctx->global_text);
|
|
|
|
if (ctx->global_text) {
|
|
|
|
free(ctx->global_text);
|
|
|
|
ctx->global_text = 0;
|
2005-08-06 00:26:14 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->global_text = NULL;
|
2006-03-06 06:57:30 +00:00
|
|
|
/* fork */
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->fork_to_background) {
|
2006-03-07 20:35:11 +00:00
|
|
|
int pid = fork();
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-03-07 20:35:11 +00:00
|
|
|
switch (pid) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case -1:
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR(PACKAGE_NAME": couldn't fork() to background: %s",
|
2008-02-20 20:30:45 +00:00
|
|
|
strerror(errno));
|
|
|
|
break;
|
2006-03-06 06:57:30 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 0:
|
|
|
|
/* child process */
|
|
|
|
usleep(25000);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
break;
|
2006-03-06 06:57:30 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
default:
|
|
|
|
/* parent process */
|
2008-07-12 10:25:05 +00:00
|
|
|
fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
|
2008-02-20 20:30:45 +00:00
|
|
|
pid);
|
|
|
|
fflush(stderr);
|
2009-07-19 20:55:41 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2006-03-06 06:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->text_buffer = malloc(ctx->max_user_text);
|
|
|
|
memset(ctx->text_buffer, 0, ctx->max_user_text);
|
|
|
|
ctx->tmpstring1 = malloc(text_buffer_size);
|
|
|
|
memset(ctx->tmpstring1, 0, text_buffer_size);
|
|
|
|
ctx->tmpstring2 = malloc(text_buffer_size);
|
|
|
|
memset(ctx->tmpstring2, 0, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->xargc = argc;
|
|
|
|
ctx->xargv = argv;
|
|
|
|
X11_create_window(ctx);
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2009-07-28 18:38:43 +00:00
|
|
|
#ifdef HAVE_LUA
|
2009-08-06 06:54:40 +00:00
|
|
|
llua_setup_info(ctx, ctx->update_interval);
|
2009-07-28 18:38:43 +00:00
|
|
|
#endif /* HAVE_LUA */
|
2009-08-03 17:58:21 +00:00
|
|
|
#ifdef XOAP
|
|
|
|
xmlInitParser();
|
|
|
|
#endif /* XOAP */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2005-11-01 06:51:48 +00:00
|
|
|
/* Set signal handlers */
|
2005-11-23 19:05:23 +00:00
|
|
|
act.sa_handler = signal_handler;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
2005-11-24 02:18:42 +00:00
|
|
|
#ifdef SA_RESTART
|
2005-11-23 19:05:23 +00:00
|
|
|
act.sa_flags |= SA_RESTART;
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2008-09-24 06:59:45 +00:00
|
|
|
if ( sigaction(SIGINT, &act, &oact) < 0
|
2009-07-26 00:26:22 +00:00
|
|
|
|| sigaction(SIGALRM, &act, &oact) < 0
|
2008-09-24 06:59:45 +00:00
|
|
|
|| sigaction(SIGUSR1, &act, &oact) < 0
|
|
|
|
|| sigaction(SIGHUP, &act, &oact) < 0
|
|
|
|
|| sigaction(SIGTERM, &act, &oact) < 0) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("error setting signal handler: %s", strerror(errno));
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-11-01 06:51:48 +00:00
|
|
|
|
2009-08-01 20:36:38 +00:00
|
|
|
#ifdef HAVE_LUA
|
|
|
|
llua_startup_hook();
|
|
|
|
#endif /* HAVE_LUA */
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-08-06 06:54:40 +00:00
|
|
|
/* Conky's main context struct */
|
|
|
|
conky_context mctx;
|
|
|
|
conky_context *ctx = &mctx;
|
|
|
|
|
2009-07-17 16:01:41 +00:00
|
|
|
#ifdef X11
|
|
|
|
char *s, *temp;
|
|
|
|
unsigned int x;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
argc_copy = argc;
|
|
|
|
argv_copy = argv;
|
|
|
|
g_signal_pending = 0;
|
2009-08-06 06:54:40 +00:00
|
|
|
memset(ctx, 0, sizeof(conky_context));
|
|
|
|
ctx->max_user_text = MAX_USER_TEXT_DEFAULT;
|
2009-07-17 16:01:41 +00:00
|
|
|
clear_net_stats();
|
|
|
|
|
|
|
|
#ifdef TCP_PORT_MONITOR
|
|
|
|
/* set default connection limit */
|
|
|
|
tcp_portmon_set_max_connections(0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* handle command line parameters that don't change configs */
|
|
|
|
#ifdef X11
|
|
|
|
if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
|
|
|
|
|| ((s = getenv("LANG")) && *s)) {
|
|
|
|
temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
|
|
|
|
if (temp == NULL) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("malloc failed");
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
for (x = 0; x < strlen(s); x++) {
|
|
|
|
temp[x] = tolower(s[x]);
|
|
|
|
}
|
|
|
|
temp[x] = 0;
|
|
|
|
if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->utf8_mode = 1;
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(temp);
|
|
|
|
}
|
|
|
|
if (!setlocale(LC_CTYPE, "")) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
#endif /* X11 */
|
|
|
|
while (1) {
|
|
|
|
int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
|
|
|
|
|
|
|
|
if (c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
case 'V':
|
|
|
|
print_version();
|
|
|
|
case 'c':
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->current_config) {
|
|
|
|
free(ctx->current_config);
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->current_config = strndup(optarg, ctx->max_user_text);
|
2009-07-17 16:01:41 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
freopen("/dev/null", "w", stderr);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
print_help(argv[0]);
|
|
|
|
return 0;
|
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
case 'C':
|
|
|
|
print_defconfig();
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
#ifdef X11
|
|
|
|
case 'w':
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->window.window = strtol(optarg, 0, 0);
|
2009-07-17 16:01:41 +00:00
|
|
|
break;
|
2009-08-01 07:34:21 +00:00
|
|
|
case 'X':
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->disp)
|
|
|
|
free(ctx->disp);
|
|
|
|
ctx->disp = strdup(optarg);
|
2009-08-01 07:34:21 +00:00
|
|
|
break;
|
2009-07-17 16:01:41 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if specified config file is valid */
|
2009-08-06 06:54:40 +00:00
|
|
|
if (ctx->current_config) {
|
2009-07-17 16:01:41 +00:00
|
|
|
struct stat sb;
|
2009-08-06 06:54:40 +00:00
|
|
|
if (stat(ctx->current_config, &sb) ||
|
2009-07-17 16:01:41 +00:00
|
|
|
(!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
|
2009-08-06 06:54:40 +00:00
|
|
|
NORM_ERR("invalid configuration file '%s'\n", ctx->current_config);
|
|
|
|
free(ctx->current_config);
|
|
|
|
ctx->current_config = 0;
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
/* load ctx->current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
|
2009-07-17 16:01:41 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
if (!ctx->current_config) {
|
2009-07-17 16:01:41 +00:00
|
|
|
/* load default config file */
|
|
|
|
char buf[DEFAULT_TEXT_BUFFER_SIZE];
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/* Try to use personal config file first */
|
|
|
|
to_real_path(buf, CONFIG_FILE);
|
|
|
|
if (buf[0] && (fp = fopen(buf, "r"))) {
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->current_config = strndup(buf, ctx->max_user_text);
|
2009-07-17 16:01:41 +00:00
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to use system config file if personal config not readable */
|
2009-08-06 06:54:40 +00:00
|
|
|
if (!ctx->current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
|
|
|
|
ctx->current_config = strndup(SYSTEM_CONFIG_FILE, ctx->max_user_text);
|
2009-07-17 16:01:41 +00:00
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No readable config found */
|
2009-08-06 06:54:40 +00:00
|
|
|
if (!ctx->current_config) {
|
2009-07-17 16:01:41 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
2009-08-06 06:54:40 +00:00
|
|
|
ctx->current_config = strdup("==builtin==");
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("no readable personal or system-wide config file found,"
|
2009-07-17 16:01:41 +00:00
|
|
|
" using builtin default");
|
|
|
|
#else
|
|
|
|
CRIT_ERR(NULL, NULL, "no readable personal or system-wide config file found");
|
|
|
|
#endif /* ! CONF_OUTPUT */
|
|
|
|
}
|
|
|
|
}
|
Revert "Undid last 3 commits, see rest of the comment for the reason:"
First of all, we may or may not agree, but I consider reverting my
commits without prior discussion as a minimum unpolite.
I also don't like sites that oblige to register, thats the very reason
why I went with noaa first (and why I use that myself).
Howver, weather.com has a couple of nice features forom an user
viewpoint:
1. Their icons can be used to add a visual quality to the weather
report.
2. They have forecast data, which is not possible to have with noaa
(using TAF its an option, but its going to be very difficult and will
be limited in time and scope).
Nobody is obliged to do anything, people who likes noaa will use noaa,
people that don't mind register or wants the additional benefit will use
weather.com.
Having libxms2 as a dragged depends is, first of all, also with other
options (rss and eve), second we can try to work around it with an
additional compilation flag if really deemed necessary.
This reverts commit d872562942812a7c71245acf7cc5f028bd4b7b4d.
2009-07-18 17:13:37 +00:00
|
|
|
|
2009-07-20 19:17:44 +00:00
|
|
|
#ifdef XOAP
|
Revert "Undid last 3 commits, see rest of the comment for the reason:"
First of all, we may or may not agree, but I consider reverting my
commits without prior discussion as a minimum unpolite.
I also don't like sites that oblige to register, thats the very reason
why I went with noaa first (and why I use that myself).
Howver, weather.com has a couple of nice features forom an user
viewpoint:
1. Their icons can be used to add a visual quality to the weather
report.
2. They have forecast data, which is not possible to have with noaa
(using TAF its an option, but its going to be very difficult and will
be limited in time and scope).
Nobody is obliged to do anything, people who likes noaa will use noaa,
people that don't mind register or wants the additional benefit will use
weather.com.
Having libxms2 as a dragged depends is, first of all, also with other
options (rss and eve), second we can try to work around it with an
additional compilation flag if really deemed necessary.
This reverts commit d872562942812a7c71245acf7cc5f028bd4b7b4d.
2009-07-18 17:13:37 +00:00
|
|
|
/* Load xoap keys, if existing */
|
|
|
|
load_xoap_keys();
|
2009-07-20 19:17:44 +00:00
|
|
|
#endif /* XOAP */
|
Revert "Undid last 3 commits, see rest of the comment for the reason:"
First of all, we may or may not agree, but I consider reverting my
commits without prior discussion as a minimum unpolite.
I also don't like sites that oblige to register, thats the very reason
why I went with noaa first (and why I use that myself).
Howver, weather.com has a couple of nice features forom an user
viewpoint:
1. Their icons can be used to add a visual quality to the weather
report.
2. They have forecast data, which is not possible to have with noaa
(using TAF its an option, but its going to be very difficult and will
be limited in time and scope).
Nobody is obliged to do anything, people who likes noaa will use noaa,
people that don't mind register or wants the additional benefit will use
weather.com.
Having libxms2 as a dragged depends is, first of all, also with other
options (rss and eve), second we can try to work around it with an
additional compilation flag if really deemed necessary.
This reverts commit d872562942812a7c71245acf7cc5f028bd4b7b4d.
2009-07-18 17:13:37 +00:00
|
|
|
|
2009-07-17 16:01:41 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
inotify_fd = inotify_init();
|
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
initialisation(&mctx, argc, argv);
|
2009-07-17 16:01:41 +00:00
|
|
|
|
2009-08-06 06:54:40 +00:00
|
|
|
main_loop(&mctx);
|
2006-01-07 07:01:22 +00:00
|
|
|
|
2007-12-31 00:00:35 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2006-03-22 19:27:31 +00:00
|
|
|
kvm_close(kd);
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
return 0;
|
2009-07-27 20:47:19 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-11-01 06:51:48 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
static void signal_handler(int sig)
|
2005-11-01 06:51:48 +00:00
|
|
|
{
|
2009-08-06 06:54:40 +00:00
|
|
|
/* signal handler is light as a feather, as it should be. we will poll
|
|
|
|
* g_signal_pending with each loop of conky and do any signal processing
|
|
|
|
* there, NOT here */
|
2009-07-26 00:26:22 +00:00
|
|
|
g_signal_pending = sig;
|
2005-11-01 06:51:48 +00:00
|
|
|
}
|