2018-05-12 16:03:00 +00:00
|
|
|
/*
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-02-27 15:14:19 +00:00
|
|
|
* Copyright (c) 2005-2021 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
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
#include "conky.h"
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <algorithm>
|
2018-05-12 23:26:31 +00:00
|
|
|
#include <cerrno>
|
|
|
|
#include <climits>
|
|
|
|
#include <clocale>
|
2010-01-03 07:59:24 +00:00
|
|
|
#include <cmath>
|
2018-05-12 23:26:31 +00:00
|
|
|
#include <cstdarg>
|
2010-01-03 07:59:24 +00:00
|
|
|
#include <ctime>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <iostream>
|
2018-05-12 23:26:31 +00:00
|
|
|
#include <memory>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2018-08-04 20:35:04 +00:00
|
|
|
#include <vector>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "text_object.h"
|
2009-12-08 05:16:11 +00:00
|
|
|
#ifdef HAVE_DIRENT_H
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <dirent.h>
|
2009-12-08 05:16:11 +00:00
|
|
|
#endif /* HAVE_DIRENT_H */
|
2008-12-23 03:59:42 +00:00
|
|
|
#include <sys/param.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <sys/time.h>
|
2009-05-19 23:14:34 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2019-02-24 20:31:46 +00:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wc99-extensions"
|
2009-05-19 23:14:34 +00:00
|
|
|
#include <sys/inotify.h>
|
2019-02-24 20:31:46 +00:00
|
|
|
#pragma clang diagnostic pop
|
2009-05-19 23:14:34 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
2022-11-28 19:23:23 +00:00
|
|
|
#ifdef BUILD_WAYLAND
|
|
|
|
#include "wl.h"
|
|
|
|
#endif /* BUILD_WAYLAND */
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_X11
|
2018-12-21 02:20:43 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
2018-05-12 23:26:31 +00:00
|
|
|
#include <X11/Xutil.h>
|
2018-12-21 02:20:43 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_XDAMAGE
|
2006-05-24 06:34:37 +00:00
|
|
|
#include <X11/extensions/Xdamage.h>
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
2010-01-10 23:35:22 +00:00
|
|
|
#ifdef BUILD_IMLIB2
|
2009-08-07 07:21:56 +00:00
|
|
|
#include "imlib2.h"
|
2010-01-10 23:35:22 +00:00
|
|
|
#endif /* BUILD_IMLIB2 */
|
2010-01-07 02:38:12 +00:00
|
|
|
#endif /* BUILD_X11 */
|
2016-07-20 16:53:48 +00:00
|
|
|
#ifdef BUILD_NCURSES
|
|
|
|
#include <ncurses.h>
|
|
|
|
#endif
|
2007-09-28 20:16:16 +00:00
|
|
|
#include <fcntl.h>
|
2008-01-06 01:35:14 +00:00
|
|
|
#include <getopt.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2018-08-12 01:51:21 +00:00
|
|
|
#if defined BUILD_RSS
|
2009-08-03 17:58:21 +00:00
|
|
|
#include <libxml/parser.h>
|
2010-05-06 15:29:09 +00:00
|
|
|
#endif
|
2010-08-29 11:31:18 +00:00
|
|
|
#ifdef BUILD_CURL
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#endif
|
2006-03-22 19:35:58 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* local headers */
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "colours.h"
|
2018-05-12 16:03:00 +00:00
|
|
|
#include "core.h"
|
2009-08-07 07:21:56 +00:00
|
|
|
#include "diskio.h"
|
2009-10-15 19:51:21 +00:00
|
|
|
#include "exec.h"
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "fonts.h"
|
2022-11-28 19:23:23 +00:00
|
|
|
#include "gui.h"
|
2022-12-26 01:39:08 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2016-05-06 11:24:52 +00:00
|
|
|
#include "fs.h"
|
2010-01-20 17:17:30 +00:00
|
|
|
#ifdef BUILD_ICONV
|
2009-10-03 18:01:33 +00:00
|
|
|
#include "iconv_tools.h"
|
|
|
|
#endif
|
2009-12-28 20:05:40 +00:00
|
|
|
#include "llua.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "logging.h"
|
|
|
|
#include "mail.h"
|
2010-04-30 17:33:21 +00:00
|
|
|
#include "nc.h"
|
2009-10-17 14:43:12 +00:00
|
|
|
#include "net_stat.h"
|
2019-06-09 21:24:16 +00:00
|
|
|
#include "specials.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "temphelper.h"
|
2009-09-03 21:53:20 +00:00
|
|
|
#include "template.h"
|
2009-10-03 15:46:59 +00:00
|
|
|
#include "timeinfo.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "top.h"
|
2010-04-18 15:52:41 +00:00
|
|
|
#ifdef BUILD_MYSQL
|
|
|
|
#include "mysql.h"
|
|
|
|
#endif /* BUILD_MYSQL */
|
2010-08-13 13:05:05 +00:00
|
|
|
#ifdef BUILD_NVIDIA
|
|
|
|
#include "nvidia.h"
|
|
|
|
#endif
|
2010-12-31 15:43:49 +00:00
|
|
|
#ifdef BUILD_CURL
|
|
|
|
#include "ccurl_thread.h"
|
|
|
|
#endif /* BUILD_CURL */
|
2008-12-15 21:40:24 +00:00
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
#include "display-output.hh"
|
2010-02-12 17:39:01 +00:00
|
|
|
#include "lua-config.hh"
|
2010-02-17 21:52:19 +00:00
|
|
|
#include "setting.hh"
|
2010-02-12 17:39:01 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* check for OS and include appropriate headers */
|
|
|
|
#if defined(__linux__)
|
|
|
|
#include "linux.h"
|
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
|
|
#include "freebsd.h"
|
2012-06-28 16:56:01 +00:00
|
|
|
#elif defined(__DragonFly__)
|
|
|
|
#include "dragonfly.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
#include "openbsd.h"
|
2018-08-20 12:32:42 +00:00
|
|
|
#endif /* __OpenBSD__ */
|
2008-12-15 21:40:24 +00:00
|
|
|
|
2022-10-06 06:08:43 +00:00
|
|
|
#include "gradient.h"
|
2021-09-21 08:30:18 +00:00
|
|
|
|
2018-12-02 16:28:28 +00:00
|
|
|
#ifdef BUILD_OLD_CONFIG
|
|
|
|
#include "convertconf.h"
|
2019-01-09 13:34:43 +00:00
|
|
|
#endif /* BUILD_OLD_CONFIG */
|
|
|
|
|
|
|
|
#ifdef BUILD_BUILTIN_CONFIG
|
|
|
|
#include "defconfig.h"
|
2018-12-02 16:28:28 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
namespace {
|
|
|
|
const char builtin_config_magic[] = "==builtin==";
|
2018-05-12 23:26:31 +00:00
|
|
|
} // namespace
|
2019-01-09 13:34:43 +00:00
|
|
|
#endif /* BUILD_BUILTIN_CONFIG */
|
2008-12-12 14:33:25 +00:00
|
|
|
|
2006-12-11 19:04:58 +00:00
|
|
|
#ifndef S_ISSOCK
|
2018-05-12 16:03:00 +00:00
|
|
|
#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
|
2006-12-11 19:04:58 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#define MAX_IF_BLOCK_DEPTH 5
|
|
|
|
|
2022-12-24 14:44:03 +00:00
|
|
|
// #define SIGNAL_BLOCKING
|
2008-09-26 21:09:48 +00:00
|
|
|
#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;
|
|
|
|
|
2010-01-02 21:31:09 +00:00
|
|
|
/* disable inotify auto reload feature if desired */
|
2018-05-12 16:03:00 +00:00
|
|
|
static conky::simple_config_setting<bool> disable_auto_reload(
|
|
|
|
"disable_auto_reload", false, false);
|
2010-01-02 21:31:09 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* two strings for internal use */
|
|
|
|
static char *tmpstring1, *tmpstring2;
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
enum spacer_state { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
|
|
|
|
template <>
|
2010-03-05 20:05:05 +00:00
|
|
|
conky::lua_traits<spacer_state>::Map conky::lua_traits<spacer_state>::map = {
|
2018-05-12 16:03:00 +00:00
|
|
|
{"none", NO_SPACER}, {"left", LEFT_SPACER}, {"right", RIGHT_SPACER}};
|
|
|
|
static conky::simple_config_setting<spacer_state> use_spacer("use_spacer",
|
|
|
|
NO_SPACER, false);
|
2010-03-05 20:05:05 +00:00
|
|
|
|
|
|
|
/* variables holding various config settings */
|
2018-05-12 16:03:00 +00:00
|
|
|
static conky::simple_config_setting<bool> short_units("short_units", false,
|
|
|
|
true);
|
|
|
|
static conky::simple_config_setting<bool> format_human_readable(
|
|
|
|
"format_human_readable", true, true);
|
2020-10-09 14:58:31 +00:00
|
|
|
conky::simple_config_setting<std::string> units_spacer("units_spacer", "",
|
|
|
|
false);
|
2010-04-30 17:06:17 +00:00
|
|
|
|
2018-08-20 12:32:42 +00:00
|
|
|
conky::simple_config_setting<bool> out_to_stdout("out_to_console",
|
2010-10-31 17:17:22 +00:00
|
|
|
// Default value is false, unless we are building without X
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-12-08 22:45:17 +00:00
|
|
|
false,
|
2010-10-31 17:17:22 +00:00
|
|
|
#else
|
2018-12-08 22:45:17 +00:00
|
|
|
true,
|
2010-10-31 17:17:22 +00:00
|
|
|
#endif
|
2018-12-08 22:45:17 +00:00
|
|
|
false);
|
2018-10-05 01:39:08 +00:00
|
|
|
conky::simple_config_setting<bool> out_to_stderr("out_to_stderr", false, false);
|
2010-06-20 17:31:17 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
int top_cpu, top_mem, top_time;
|
2010-01-07 18:14:53 +00:00
|
|
|
#ifdef BUILD_IOSTATS
|
2009-08-07 07:24:24 +00:00
|
|
|
int top_io;
|
|
|
|
#endif
|
2009-09-03 21:13:14 +00:00
|
|
|
int top_running;
|
2010-09-11 12:25:19 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* Update interval */
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::range_config_setting<double> update_interval(
|
|
|
|
"update_interval", 0.0, std::numeric_limits<double>::infinity(), 3.0, true);
|
|
|
|
conky::range_config_setting<double> update_interval_on_battery(
|
|
|
|
"update_interval_on_battery", 0.0, std::numeric_limits<double>::infinity(),
|
|
|
|
NOBATTERY, true);
|
2018-05-03 12:34:48 +00:00
|
|
|
conky::simple_config_setting<std::string> detect_battery("detect_battery",
|
2018-05-12 16:03:00 +00:00
|
|
|
std::string("BAT0"),
|
|
|
|
false);
|
2010-09-11 12:25:19 +00:00
|
|
|
static bool on_battery = false;
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
double active_update_interval() {
|
|
|
|
return (on_battery ? update_interval_on_battery : update_interval)
|
|
|
|
.get(*state);
|
|
|
|
}
|
2010-09-11 12:25:19 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void music_player_interval_setting::lua_setter(lua::state &l, bool init) {
|
|
|
|
lua::stack_sentry s(l, -2);
|
2010-09-11 12:45:19 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
if (l.isnil(-2)) {
|
|
|
|
l.checkstack(1);
|
|
|
|
l.pushnumber(update_interval.get(l));
|
|
|
|
l.replace(-3);
|
|
|
|
}
|
2010-09-11 12:45:19 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
Base::lua_setter(l, init);
|
2010-09-11 12:45:19 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
++s;
|
2010-09-11 12:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
music_player_interval_setting music_player_interval;
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
void *global_cpu = nullptr;
|
2018-05-12 16:03:00 +00:00
|
|
|
static conky::range_config_setting<unsigned int> max_text_width(
|
|
|
|
"max_text_width", 0, std::numeric_limits<unsigned int>::max(), 0, true);
|
2008-12-15 21:40:24 +00:00
|
|
|
|
2010-02-14 21:58:02 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
|
|
extern kvm_t *kd;
|
|
|
|
#endif
|
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* prototypes for internally used functions */
|
2018-05-12 23:26:31 +00:00
|
|
|
static void signal_handler(int /*sig*/);
|
|
|
|
static void reload_config();
|
2008-03-29 11:35:02 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static const char *suffixes[] = {_nop("B"), _nop("KiB"), _nop("MiB"),
|
|
|
|
_nop("GiB"), _nop("TiB"), _nop("PiB"),
|
|
|
|
""};
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* text size */
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
int text_start_x, text_start_y; /* text start position in window */
|
|
|
|
int text_offset_x, text_offset_y; /* offset for start position */
|
|
|
|
int text_width = 1,
|
|
|
|
text_height = 1; /* initially 1 so no zero-sized window is created */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* struct that has all info to be shared between
|
|
|
|
* instances of the same text object */
|
|
|
|
struct information info;
|
|
|
|
|
|
|
|
/* path to config file */
|
2010-03-04 10:42:38 +00:00
|
|
|
std::string current_config;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* set to 1 if you want all text to be in uppercase */
|
2018-05-12 16:03:00 +00:00
|
|
|
static conky::simple_config_setting<bool> stuff_in_uppercase("uppercase", false,
|
|
|
|
true);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2020-01-21 21:29:17 +00:00
|
|
|
static conky::simple_config_setting<bool> stuff_in_lowercase("lowercase", false,
|
|
|
|
true);
|
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* Run how many times? */
|
2018-05-12 16:03:00 +00:00
|
|
|
static conky::range_config_setting<unsigned long> total_run_times(
|
|
|
|
"total_run_times", 0, std::numeric_limits<unsigned long>::max(), 0, true);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* fork? */
|
2018-05-12 16:03:00 +00:00
|
|
|
static conky::simple_config_setting<bool> fork_to_background("background",
|
|
|
|
false, false);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2010-01-26 21:05:04 +00:00
|
|
|
/* set to 0 after the first time conky is run, so we don't fork again after the
|
|
|
|
* first forking */
|
2018-12-23 21:38:00 +00:00
|
|
|
int first_pass = 1;
|
|
|
|
int argc_copy;
|
|
|
|
char **argv_copy;
|
2010-01-26 21:05:04 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::range_config_setting<int> cpu_avg_samples("cpu_avg_samples", 1, 14, 2,
|
|
|
|
true);
|
|
|
|
conky::range_config_setting<int> net_avg_samples("net_avg_samples", 1, 14, 2,
|
|
|
|
true);
|
|
|
|
conky::range_config_setting<int> diskio_avg_samples("diskio_avg_samples", 1, 14,
|
|
|
|
2, true);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2022-10-06 06:08:43 +00:00
|
|
|
/* graph */
|
2018-10-18 23:14:03 +00:00
|
|
|
conky::simple_config_setting<bool> show_graph_scale("show_graph_scale", false,
|
|
|
|
false);
|
|
|
|
conky::simple_config_setting<bool> show_graph_range("show_graph_range", false,
|
|
|
|
false);
|
2008-04-13 04:10:35 +00:00
|
|
|
|
2022-10-06 06:08:43 +00:00
|
|
|
enum gradient_state { RGB_GRADIENT = 0, HSV_GRADIENT, HCL_GRADIENT };
|
|
|
|
template <>
|
|
|
|
conky::lua_traits<gradient_state>::Map conky::lua_traits<gradient_state>::map =
|
|
|
|
{{"rgb", RGB_GRADIENT}, {"hsv", HSV_GRADIENT}, {"hcl", HCL_GRADIENT}};
|
|
|
|
static conky::simple_config_setting<gradient_state> graph_gradient_mode(
|
|
|
|
"graph_gradient_mode", RGB_GRADIENT, false);
|
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* Position on the screen */
|
2018-10-18 23:14:03 +00:00
|
|
|
conky::simple_config_setting<int> gap_x("gap_x", 5, true);
|
|
|
|
conky::simple_config_setting<int> gap_y("gap_y", 60, true);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* border */
|
2018-10-18 23:14:03 +00:00
|
|
|
conky::simple_config_setting<bool> draw_borders("draw_borders", false, false);
|
|
|
|
conky::simple_config_setting<bool> draw_graph_borders("draw_graph_borders",
|
|
|
|
true, false);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::range_config_setting<char> stippled_borders(
|
|
|
|
"stippled_borders", 0, std::numeric_limits<char>::max(), 0, true);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
conky::simple_config_setting<bool> draw_shades("draw_shades", true, false);
|
|
|
|
conky::simple_config_setting<bool> draw_outline("draw_outline", false, false);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
/* fixed size/pos is set if wm/user changes them */
|
2018-10-18 23:14:03 +00:00
|
|
|
int fixed_size = 0, fixed_pos = 0;
|
2005-08-06 00:26:14 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
conky::range_config_setting<int> minimum_height("minimum_height", 0,
|
|
|
|
std::numeric_limits<int>::max(),
|
|
|
|
5, true);
|
|
|
|
conky::range_config_setting<int> minimum_width("minimum_width", 0,
|
|
|
|
std::numeric_limits<int>::max(),
|
|
|
|
5, true);
|
|
|
|
conky::range_config_setting<int> maximum_width("maximum_width", 0,
|
|
|
|
std::numeric_limits<int>::max(),
|
|
|
|
0, true);
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
static bool isutf8(const char *envvar) {
|
|
|
|
char *s = getenv(envvar);
|
2018-05-12 23:26:31 +00:00
|
|
|
if (s != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
std::string temp = s;
|
|
|
|
std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
|
|
|
|
if ((temp.find("utf-8") != std::string::npos) ||
|
|
|
|
(temp.find("utf8") != std::string::npos)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2010-04-30 15:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* UTF-8 */
|
2017-12-07 20:00:38 +00:00
|
|
|
conky::simple_config_setting<bool> utf8_mode("override_utf8_locale",
|
2018-05-12 16:03:00 +00:00
|
|
|
isutf8("LC_ALL") ||
|
|
|
|
isutf8("LC_CTYPE") ||
|
|
|
|
isutf8("LANG"),
|
|
|
|
false);
|
2010-04-30 15:51:30 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* maximum size of config TEXT buffer, i.e. below TEXT line. */
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::range_config_setting<unsigned int> max_user_text(
|
|
|
|
"max_user_text", 47, std::numeric_limits<unsigned int>::max(),
|
|
|
|
MAX_USER_TEXT_DEFAULT, false);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* maximum size of individual text buffers, ie $exec buffer size */
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::range_config_setting<unsigned int> text_buffer_size(
|
|
|
|
"text_buffer_size", DEFAULT_TEXT_BUFFER_SIZE,
|
|
|
|
std::numeric_limits<unsigned int>::max(), DEFAULT_TEXT_BUFFER_SIZE, false);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* pad percentages to decimals? */
|
2010-08-25 17:19:10 +00:00
|
|
|
static conky::simple_config_setting<int> pad_percents("pad_percents", 0, false);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
static char *global_text = nullptr;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
char *get_global_text() { return global_text; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
long global_text_lines;
|
|
|
|
|
|
|
|
static int total_updates;
|
|
|
|
static int updatereset;
|
|
|
|
|
2010-06-26 10:33:55 +00:00
|
|
|
std::unique_ptr<lua::state> state;
|
2010-02-24 19:51:33 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void set_updatereset(int i) { updatereset = i; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
int get_updatereset() { return updatereset; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
int get_total_updates() { return total_updates; }
|
2009-11-29 18:48:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
int calc_text_width(const char *s) {
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) return display_output()->calc_text_width(s);
|
2009-09-20 01:02:56 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
size_t slen = strlen(s);
|
|
|
|
return slen;
|
2009-11-07 11:21:48 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
int dpi_scale(int value) {
|
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output()) {
|
|
|
|
return display_output()->dpi_scale(value);
|
2021-04-18 16:05:28 +00:00
|
|
|
} else {
|
2021-04-10 12:58:37 +00:00
|
|
|
return value;
|
2021-04-18 16:05:28 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#else /* BUILD_GUI */
|
2021-04-18 16:05:28 +00:00
|
|
|
return value;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2021-04-08 09:26:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 16:37:51 +00:00
|
|
|
#ifdef BUILD_GUI
|
2023-02-24 13:13:19 +00:00
|
|
|
conky::gradient_factory *create_gradient_factory(int width, Colour first_colour,
|
|
|
|
Colour last_colour) {
|
2022-10-06 06:08:43 +00:00
|
|
|
switch (graph_gradient_mode.get(*state)) {
|
|
|
|
case RGB_GRADIENT:
|
|
|
|
return new conky::rgb_gradient_factory(width, first_colour, last_colour);
|
|
|
|
case HSV_GRADIENT:
|
|
|
|
return new conky::hsv_gradient_factory(width, first_colour, last_colour);
|
|
|
|
case HCL_GRADIENT:
|
|
|
|
return new conky::hcl_gradient_factory(width, first_colour, last_colour);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-10-06 16:37:51 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2022-10-06 06:08:43 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* formatted text to render on screen, generated in generate_text(),
|
|
|
|
* drawn in draw_stuff() */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
static char *text_buffer;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* quite boring functions */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static inline void for_each_line(char *b, int f(char *, int)) {
|
|
|
|
char *ps, *pe;
|
|
|
|
int special_index = 0; /* specials index */
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (b == nullptr) { return; }
|
2018-05-12 23:26:31 +00:00
|
|
|
for (ps = b, pe = b; *pe != 0; pe++) {
|
2018-05-12 16:03:00 +00:00
|
|
|
if (*pe == '\n') {
|
|
|
|
*pe = '\0';
|
|
|
|
special_index = f(ps, special_index);
|
|
|
|
*pe = '\n';
|
|
|
|
ps = pe + 1;
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (ps < pe) { f(ps, special_index); }
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static void convert_escapes(char *buf) {
|
|
|
|
char *p = buf, *s = buf;
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
while (*s != 0) {
|
2018-05-12 16:03:00 +00:00
|
|
|
if (*s == '\\') {
|
|
|
|
s++;
|
|
|
|
if (*s == 'n') {
|
|
|
|
*p++ = '\n';
|
|
|
|
} else if (*s == '\\') {
|
|
|
|
*p++ = '\\';
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
} else {
|
|
|
|
*p++ = *s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
2009-08-05 22:46:51 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* Prints anything normally printed with snprintf according to the current value
|
|
|
|
* of use_spacer. Actually slightly more flexible than snprintf, as you can
|
|
|
|
* safely specify the destination buffer as one of your inputs. */
|
2018-05-12 16:03:00 +00:00
|
|
|
int spaced_print(char *buf, int size, const char *format, int width, ...) {
|
|
|
|
int len = 0;
|
|
|
|
va_list argp;
|
|
|
|
char *tempbuf;
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (size < 1) { return 0; }
|
2018-12-02 16:28:28 +00:00
|
|
|
tempbuf = new char[size];
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
// Passes the varargs along to vsnprintf
|
|
|
|
va_start(argp, width);
|
|
|
|
vsnprintf(tempbuf, size, format, argp);
|
|
|
|
va_end(argp);
|
|
|
|
|
|
|
|
switch (use_spacer.get(*state)) {
|
|
|
|
case NO_SPACER:
|
|
|
|
len = snprintf(buf, size, "%s", tempbuf);
|
|
|
|
break;
|
|
|
|
case LEFT_SPACER:
|
|
|
|
len = snprintf(buf, size, "%*s", width, tempbuf);
|
|
|
|
break;
|
|
|
|
case RIGHT_SPACER:
|
|
|
|
len = snprintf(buf, size, "%-*s", width, tempbuf);
|
|
|
|
break;
|
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
delete[] tempbuf;
|
2018-05-12 16:03:00 +00:00
|
|
|
return len;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* print percentage values
|
|
|
|
*
|
|
|
|
* - i.e., unsigned values between 0 and 100
|
|
|
|
* - respect the value of pad_percents */
|
2018-05-12 16:03:00 +00:00
|
|
|
int percent_print(char *buf, int size, unsigned value) {
|
|
|
|
return spaced_print(buf, size, "%u", pad_percents.get(*state), value);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* converts from bytes to human readable format (K, M, G, T)
|
|
|
|
*
|
|
|
|
* The algorithm always divides by 1024, as unit-conversion of byte
|
|
|
|
* counts suggests. But for output length determination we need to
|
|
|
|
* compare with 1000 here, as we print in decimal form. */
|
2018-05-12 16:03:00 +00:00
|
|
|
void human_readable(long long num, char *buf, int size) {
|
|
|
|
const char **suffix = suffixes;
|
|
|
|
float fnum;
|
|
|
|
int precision;
|
|
|
|
int width;
|
2018-12-16 17:05:11 +00:00
|
|
|
const char *format;
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
/* Possibly just output as usual, for example for stdout usage */
|
2018-05-13 18:27:58 +00:00
|
|
|
if (!format_human_readable.get(*state)) {
|
2018-05-12 16:03:00 +00:00
|
|
|
spaced_print(buf, size, "%lld", 6, num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (short_units.get(*state)) {
|
2020-10-09 14:58:31 +00:00
|
|
|
width = 5;
|
|
|
|
format = "%.*f%s%.1s";
|
2018-05-12 16:03:00 +00:00
|
|
|
} else {
|
2020-10-09 14:58:31 +00:00
|
|
|
width = 7;
|
|
|
|
format = "%.*f%s%-.3s";
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2020-10-09 14:58:31 +00:00
|
|
|
width += strlen(units_spacer.get(*state).c_str());
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
if (llabs(num) < 1000LL) {
|
2018-05-12 23:26:31 +00:00
|
|
|
spaced_print(buf, size, format, width, 0, static_cast<float>(num),
|
2020-10-09 14:58:31 +00:00
|
|
|
units_spacer.get(*state).c_str(), _(*suffix));
|
2018-05-12 16:03:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
while (llabs(num / 1024) >= 1000LL && (**(suffix + 2) != 0)) {
|
2018-05-12 16:03:00 +00:00
|
|
|
num /= 1024;
|
|
|
|
suffix++;
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix++;
|
|
|
|
fnum = num / 1024.0;
|
|
|
|
|
|
|
|
/* fnum should now be < 1000, so looks like 'AAA.BBBBB'
|
|
|
|
*
|
|
|
|
* The goal is to always have a significance of 3, by
|
|
|
|
* adjusting the decimal part of the number. Sample output:
|
|
|
|
* 123MiB
|
|
|
|
* 23.4GiB
|
|
|
|
* 5.12B
|
|
|
|
* so the point of alignment resides between number and unit. The
|
|
|
|
* upside of this is that there is minimal padding necessary, though
|
|
|
|
* there should be a way to make alignment take place at the decimal
|
|
|
|
* dot (then with fixed width decimal part).
|
|
|
|
*
|
|
|
|
* Note the repdigits below: when given a precision value, printf()
|
|
|
|
* rounds the float to it, not just cuts off the remaining digits. So
|
|
|
|
* e.g. 99.95 with a precision of 1 gets 100.0, which again should be
|
|
|
|
* printed with a precision of 0. Yay. */
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
precision = 0; /* print 100-999 without decimal part */
|
|
|
|
if (fnum < 99.95) { precision = 1; /* print 10-99 with one decimal place */ }
|
|
|
|
if (fnum < 9.995) { precision = 2; /* print 0-9 with two decimal places */ }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2020-10-09 14:58:31 +00:00
|
|
|
spaced_print(buf, size, format, width, precision, fnum,
|
|
|
|
units_spacer.get(*state).c_str(), _(*suffix));
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
2009-05-13 00:05:51 +00:00
|
|
|
|
2009-08-07 07:24:24 +00:00
|
|
|
/* global object list root element */
|
|
|
|
static struct text_object global_root_object;
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2023-01-02 23:54:53 +00:00
|
|
|
static Colour current_text_color;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2023-01-02 23:54:53 +00:00
|
|
|
void set_current_text_color(Colour colour) { current_text_color = colour; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2023-01-02 23:54:53 +00:00
|
|
|
Colour get_current_text_color() { return current_text_color; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static void extract_variable_text(const char *p) {
|
|
|
|
free_text_objects(&global_root_object);
|
2018-12-02 16:28:28 +00:00
|
|
|
delete_block_and_zero(tmpstring1);
|
|
|
|
delete_block_and_zero(tmpstring2);
|
|
|
|
delete_block_and_zero(text_buffer);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
extract_variable_text_internal(&global_root_object, p);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void parse_conky_vars(struct text_object *root, const char *txt, char *p,
|
|
|
|
int p_max_size) {
|
|
|
|
extract_variable_text_internal(root, txt);
|
|
|
|
generate_text_internal(p, p_max_size, *root);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-29 19:34:23 +00:00
|
|
|
/* IFBLOCK jumping algorithm
|
|
|
|
*
|
|
|
|
* This is easier as it looks like:
|
|
|
|
* - each IF checks it's condition
|
|
|
|
* - on FALSE: jump
|
|
|
|
* - on TRUE: don't care
|
|
|
|
* - each ELSE jumps unconditionally
|
|
|
|
* - each ENDIF is silently being ignored
|
|
|
|
*
|
|
|
|
* Why this works (or: how jumping works):
|
|
|
|
* Jumping means to overwrite the "obj" variable of the loop and set it to the
|
|
|
|
* target (i.e. the corresponding ELSE or ENDIF). After that, the for-loop does
|
|
|
|
* the rest: as regularly, "obj" is being updated to point to obj->next, so
|
|
|
|
* object parsing continues right after the corresponding ELSE or ENDIF. This
|
|
|
|
* means that if we find an ELSE, it's corresponding IF must not have jumped,
|
|
|
|
* so we need to jump always. If we encounter an ENDIF, it's corresponding IF
|
|
|
|
* or ELSE has not jumped, and there is nothing to do.
|
|
|
|
*/
|
2018-05-12 16:03:00 +00:00
|
|
|
void generate_text_internal(char *p, int p_max_size, struct text_object root) {
|
|
|
|
struct text_object *obj;
|
|
|
|
size_t a;
|
2010-05-05 16:46:04 +00:00
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (p == nullptr) { return; }
|
2010-05-05 16:46:04 +00:00
|
|
|
|
2010-01-20 17:17:30 +00:00
|
|
|
#ifdef BUILD_ICONV
|
2018-05-12 16:03:00 +00:00
|
|
|
char *buff_in;
|
2009-12-17 21:19:58 +00:00
|
|
|
|
2018-12-02 16:28:28 +00:00
|
|
|
buff_in = new char[p_max_size];
|
2018-05-12 16:03:00 +00:00
|
|
|
memset(buff_in, 0, p_max_size);
|
2010-01-20 17:17:30 +00:00
|
|
|
#endif /* BUILD_ICONV */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
p[0] = 0;
|
|
|
|
obj = root.next;
|
2018-05-12 23:26:31 +00:00
|
|
|
while ((obj != nullptr) && p_max_size > 0) {
|
2018-05-12 16:03:00 +00:00
|
|
|
/* check callbacks for existence and act accordingly */
|
2018-05-12 23:26:31 +00:00
|
|
|
if (obj->callbacks.print != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
(*obj->callbacks.print)(obj, p, p_max_size);
|
2018-05-12 23:26:31 +00:00
|
|
|
} else if (obj->callbacks.iftest != nullptr) {
|
|
|
|
if ((*obj->callbacks.iftest)(obj) == 0) {
|
2018-05-12 16:03:00 +00:00
|
|
|
DBGP2("jumping");
|
2018-05-13 18:20:39 +00:00
|
|
|
if (obj->ifblock_next != nullptr) { obj = obj->ifblock_next; }
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-05-12 23:26:31 +00:00
|
|
|
} else if (obj->callbacks.barval != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
new_bar(obj, p, p_max_size, (*obj->callbacks.barval)(obj));
|
2018-05-12 23:26:31 +00:00
|
|
|
} else if (obj->callbacks.gaugeval != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
new_gauge(obj, p, p_max_size, (*obj->callbacks.gaugeval)(obj));
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 23:26:31 +00:00
|
|
|
} else if (obj->callbacks.graphval != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
new_graph(obj, p, p_max_size, (*obj->callbacks.graphval)(obj));
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 23:26:31 +00:00
|
|
|
} else if (obj->callbacks.percentage != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
percent_print(p, p_max_size, (*obj->callbacks.percentage)(obj));
|
|
|
|
}
|
2009-11-19 23:25:45 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
a = strlen(p);
|
2010-01-20 17:17:30 +00:00
|
|
|
#ifdef BUILD_ICONV
|
2018-05-12 16:03:00 +00:00
|
|
|
iconv_convert(&a, buff_in, p, p_max_size);
|
2010-01-20 17:17:30 +00:00
|
|
|
#endif /* BUILD_ICONV */
|
2018-05-12 16:03:00 +00:00
|
|
|
p += a;
|
|
|
|
p_max_size -= a;
|
|
|
|
(*p) = 0;
|
2009-11-29 19:34:23 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
obj = obj->next;
|
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
/* load any new fonts we may have had */
|
|
|
|
load_fonts(utf8_mode.get(*state));
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2010-01-20 17:17:30 +00:00
|
|
|
#ifdef BUILD_ICONV
|
2018-12-08 22:45:17 +00:00
|
|
|
delete[] buff_in;
|
2010-01-20 17:17:30 +00:00
|
|
|
#endif /* BUILD_ICONV */
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void evaluate(const char *text, char *p, int p_max_size) {
|
2018-05-12 23:26:31 +00:00
|
|
|
struct text_object subroot {};
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2019-03-03 16:45:02 +00:00
|
|
|
/**
|
|
|
|
* Consider expressions like: ${execp echo '${execp echo hi}'}
|
2019-04-23 06:07:20 +00:00
|
|
|
* These would require run extract_variable_text_internal() before
|
|
|
|
* callbacks and generate_text_internal() after callbacks.
|
2019-03-03 16:45:02 +00:00
|
|
|
*/
|
2019-04-23 06:44:14 +00:00
|
|
|
extract_variable_text_internal(&subroot, text);
|
2019-04-23 06:07:20 +00:00
|
|
|
generate_text_internal(p, p_max_size, subroot);
|
2018-05-12 16:03:00 +00:00
|
|
|
DBGP2("evaluated '%s' to '%s'", text, p);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
free_text_objects(&subroot);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double current_update_time, next_update_time, last_update_time;
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
static void generate_text() {
|
2018-05-12 16:03:00 +00:00
|
|
|
char *p;
|
|
|
|
unsigned int i, j, k;
|
|
|
|
special_count = 0;
|
|
|
|
|
|
|
|
current_update_time = get_time();
|
|
|
|
|
|
|
|
/* clears netstats info, calls conky::run_all_callbacks(), and changes
|
|
|
|
* some info.mem entries */
|
|
|
|
update_stuff();
|
|
|
|
|
|
|
|
/* populate the text buffer; generate_text_internal() iterates through
|
|
|
|
* global_root_object (an instance of the text_object struct) and calls
|
|
|
|
* any callbacks that were set on startup by construct_text_object(). */
|
|
|
|
p = text_buffer;
|
|
|
|
|
|
|
|
generate_text_internal(p, max_user_text.get(*state), global_root_object);
|
|
|
|
unsigned int mw = max_text_width.get(*state);
|
|
|
|
unsigned int tbs = text_buffer_size.get(*state);
|
|
|
|
if (mw > 0) {
|
|
|
|
for (i = 0, j = 0; p[i] != 0; i++) {
|
2018-05-12 23:26:31 +00:00
|
|
|
if (p[i] == '\n') {
|
2018-05-12 16:03:00 +00:00
|
|
|
j = 0;
|
2018-05-12 23:26:31 +00:00
|
|
|
} else if (j == mw) {
|
2018-05-12 16:03:00 +00:00
|
|
|
k = i + strlen(p + i) + 1;
|
|
|
|
if (k < tbs) {
|
|
|
|
while (k != i) {
|
|
|
|
p[k] = p[k - 1];
|
|
|
|
k--;
|
|
|
|
}
|
|
|
|
p[k] = '\n';
|
|
|
|
j = 0;
|
2018-05-12 23:26:31 +00:00
|
|
|
} else {
|
2018-05-12 16:03:00 +00:00
|
|
|
NORM_ERR(
|
|
|
|
"The end of the text_buffer is reached, increase "
|
|
|
|
"\"text_buffer_size\"");
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-12 16:03:00 +00:00
|
|
|
j++;
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
if (stuff_in_uppercase.get(*state)) {
|
|
|
|
char *tmp_p;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
tmp_p = text_buffer;
|
2018-05-12 23:26:31 +00:00
|
|
|
while (*tmp_p != 0) {
|
2019-02-23 19:43:44 +00:00
|
|
|
*tmp_p = toupper(static_cast<unsigned char>(*tmp_p));
|
2018-05-12 16:03:00 +00:00
|
|
|
tmp_p++;
|
|
|
|
}
|
2020-01-21 21:29:17 +00:00
|
|
|
} else if (stuff_in_lowercase.get(*state)) {
|
|
|
|
char *tmp_p;
|
|
|
|
|
|
|
|
tmp_p = text_buffer;
|
|
|
|
while (*tmp_p != 0) {
|
|
|
|
*tmp_p = tolower(static_cast<unsigned char>(*tmp_p));
|
|
|
|
tmp_p++;
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double ui = active_update_interval();
|
|
|
|
double time = get_time();
|
|
|
|
next_update_time += ui;
|
2018-05-12 23:26:31 +00:00
|
|
|
if (next_update_time < time || next_update_time > time + ui) {
|
2018-05-12 16:03:00 +00:00
|
|
|
next_update_time = time - fmod(time, ui) + ui;
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2021-04-25 00:05:45 +00:00
|
|
|
last_update_time = current_update_time;
|
2018-05-12 16:03:00 +00:00
|
|
|
total_updates++;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
int get_string_width(const char *s) { return *s != 0 ? calc_text_width(s) : 0; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
int get_border_total() {
|
|
|
|
return dpi_scale(border_inner_margin.get(*state)) +
|
|
|
|
dpi_scale(border_outer_margin.get(*state)) +
|
|
|
|
dpi_scale(border_width.get(*state));
|
2010-04-22 23:22:22 +00:00
|
|
|
}
|
|
|
|
|
2022-12-24 14:44:03 +00:00
|
|
|
void remove_first_char(char *s) { memmove(s, s + 1, strlen(s)); }
|
2022-11-28 19:23:23 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static int get_string_width_special(char *s, int special_index) {
|
|
|
|
char *p, *final;
|
|
|
|
special_t *current = specials;
|
|
|
|
int width = 0;
|
|
|
|
long i;
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (s == nullptr) { return 0; }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output() == nullptr || !display_output()->graphical()) {
|
|
|
|
return strlen(s);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
p = strndup(s, text_buffer_size.get(*state));
|
|
|
|
final = p;
|
|
|
|
|
2022-11-28 19:23:23 +00:00
|
|
|
for (i = 0; i <= special_index; i++) { current = current->next; }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
while (*p != 0) {
|
2018-05-12 16:03:00 +00:00
|
|
|
if (*p == SPECIAL_CHAR) {
|
|
|
|
/* shift everything over by 1 so that the special char
|
|
|
|
* doesn't mess up the size calculation */
|
2022-11-28 19:23:23 +00:00
|
|
|
remove_first_char(p);
|
|
|
|
/*for (i = 0; i < static_cast<long>(strlen(p)); i++) {
|
2018-05-12 16:03:00 +00:00
|
|
|
*(p + i) = *(p + i + 1);
|
2022-11-28 19:23:23 +00:00
|
|
|
}*/
|
2018-05-12 16:03:00 +00:00
|
|
|
if (current->type == GRAPH || current->type == GAUGE ||
|
|
|
|
current->type == BAR) {
|
|
|
|
width += current->width;
|
|
|
|
}
|
|
|
|
if (current->type == FONT) {
|
|
|
|
// put all following text until the next fontchange/stringend in
|
|
|
|
// influenced_by_font but do not include specials
|
|
|
|
char *influenced_by_font = strdup(p);
|
|
|
|
special_t *current_after_font = current;
|
2022-11-28 19:23:23 +00:00
|
|
|
// influenced_by_font gets special chars removed, so after this loop i
|
|
|
|
// counts the number of letters (not special chars) influenced by font
|
2018-05-12 16:03:00 +00:00
|
|
|
for (i = 0; influenced_by_font[i] != 0; i++) {
|
|
|
|
if (influenced_by_font[i] == SPECIAL_CHAR) {
|
|
|
|
// remove specials and stop at fontchange
|
|
|
|
current_after_font = current_after_font->next;
|
|
|
|
if (current_after_font->type == FONT) {
|
|
|
|
influenced_by_font[i] = 0;
|
|
|
|
break;
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2022-11-28 19:23:23 +00:00
|
|
|
remove_first_char(&influenced_by_font[i]);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// add the length of influenced_by_font in the new font to width
|
|
|
|
int orig_font = selected_font;
|
|
|
|
selected_font = current->font_added;
|
|
|
|
width += calc_text_width(influenced_by_font);
|
|
|
|
selected_font = orig_font;
|
|
|
|
free(influenced_by_font);
|
2022-11-28 19:23:23 +00:00
|
|
|
// make sure the chars counted in the new font are not again counted
|
2018-05-12 16:03:00 +00:00
|
|
|
// in the old font
|
|
|
|
int specials_skipped = 0;
|
|
|
|
while (i > 0) {
|
2022-11-28 19:23:23 +00:00
|
|
|
if (p[specials_skipped] != SPECIAL_CHAR) {
|
|
|
|
remove_first_char(&p[specials_skipped]);
|
|
|
|
// i only counts non-special chars, so only decrement it for those
|
|
|
|
i--;
|
2018-05-12 23:26:31 +00:00
|
|
|
} else {
|
2018-05-12 16:03:00 +00:00
|
|
|
specials_skipped++;
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
current = current->next;
|
|
|
|
} else {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 18:20:39 +00:00
|
|
|
if (strlen(final) > 1) { width += calc_text_width(final); }
|
2018-05-12 16:03:00 +00:00
|
|
|
free(final);
|
|
|
|
return width;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int text_size_updater(char *s, int special_index);
|
|
|
|
|
|
|
|
int last_font_height;
|
2018-10-18 23:14:03 +00:00
|
|
|
void update_text_area() {
|
2018-05-12 16:03:00 +00:00
|
|
|
int x = 0, y = 0;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() == nullptr || !display_output()->graphical()) { return; }
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
/* update text size if it isn't fixed */
|
2009-08-07 07:24:24 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2018-05-12 23:26:31 +00:00
|
|
|
if (fixed_size == 0)
|
2018-05-12 16:03:00 +00:00
|
|
|
#endif
|
|
|
|
{
|
2018-10-18 23:14:03 +00:00
|
|
|
text_width = dpi_scale(minimum_width.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
text_height = 0;
|
|
|
|
last_font_height = font_height();
|
|
|
|
for_each_line(text_buffer, text_size_updater);
|
|
|
|
text_width += 1;
|
2018-10-18 23:14:03 +00:00
|
|
|
if (text_height < dpi_scale(minimum_height.get(*state))) {
|
|
|
|
text_height = dpi_scale(minimum_height.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
int mw = dpi_scale(maximum_width.get(*state));
|
2018-05-13 18:20:39 +00:00
|
|
|
if (text_width > mw && mw > 0) { text_width = mw; }
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alignment align = text_alignment.get(*state);
|
|
|
|
/* get text position on workarea */
|
|
|
|
switch (align) {
|
|
|
|
case TOP_LEFT:
|
|
|
|
case TOP_RIGHT:
|
|
|
|
case TOP_MIDDLE:
|
2018-10-18 23:14:03 +00:00
|
|
|
y = workarea[1] + dpi_scale(gap_y.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BOTTOM_LEFT:
|
|
|
|
case BOTTOM_RIGHT:
|
|
|
|
case BOTTOM_MIDDLE:
|
|
|
|
default:
|
2018-10-18 23:14:03 +00:00
|
|
|
y = workarea[3] - text_height - dpi_scale(gap_y.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDDLE_LEFT:
|
|
|
|
case MIDDLE_RIGHT:
|
|
|
|
case MIDDLE_MIDDLE:
|
2018-12-08 22:45:17 +00:00
|
|
|
y = workarea[1] + (workarea[3] - workarea[1]) / 2 - text_height / 2 -
|
2018-10-18 23:14:03 +00:00
|
|
|
dpi_scale(gap_y.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (align) {
|
|
|
|
case TOP_LEFT:
|
|
|
|
case BOTTOM_LEFT:
|
|
|
|
case MIDDLE_LEFT:
|
|
|
|
default:
|
2018-10-18 23:14:03 +00:00
|
|
|
x = workarea[0] + dpi_scale(gap_x.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOP_RIGHT:
|
|
|
|
case BOTTOM_RIGHT:
|
|
|
|
case MIDDLE_RIGHT:
|
2018-10-18 23:14:03 +00:00
|
|
|
x = workarea[2] - text_width - dpi_scale(gap_x.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOP_MIDDLE:
|
|
|
|
case BOTTOM_MIDDLE:
|
|
|
|
case MIDDLE_MIDDLE:
|
2018-12-08 22:45:17 +00:00
|
|
|
x = workarea[0] + (workarea[2] - workarea[0]) / 2 - text_width / 2 -
|
2018-10-18 23:14:03 +00:00
|
|
|
dpi_scale(gap_x.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2018-05-12 16:03:00 +00:00
|
|
|
if (align == NONE) { // Let the WM manage the window
|
|
|
|
x = window.x;
|
|
|
|
y = window.y;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
fixed_pos = 1;
|
|
|
|
fixed_size = 1;
|
|
|
|
}
|
2009-11-13 20:35:49 +00:00
|
|
|
#endif /* OWN_WINDOW */
|
2009-08-07 07:24:24 +00:00
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
if (own_window.get(*state) && (fixed_pos == 0)) {
|
2018-05-12 16:03:00 +00:00
|
|
|
int border_total = get_border_total();
|
|
|
|
text_start_x = text_start_y = border_total;
|
|
|
|
window.x = x - border_total;
|
|
|
|
window.y = y - border_total;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
text_start_x = x;
|
|
|
|
text_start_y = y;
|
|
|
|
}
|
|
|
|
/* update lua window globals */
|
|
|
|
llua_update_window_table(text_start_x, text_start_y, text_width, text_height);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* drawing stuff */
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static int cur_x, cur_y; /* current x and y for drawing */
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
2018-10-18 23:14:03 +00:00
|
|
|
// draw_mode also without BUILD_GUI because we only need to print to stdout with
|
2018-05-12 16:03:00 +00:00
|
|
|
// FG
|
|
|
|
static int draw_mode; /* FG, BG or OUTLINE */
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2023-01-02 23:54:53 +00:00
|
|
|
/*static*/ Colour current_color;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2021-01-29 23:25:58 +00:00
|
|
|
static int saved_coordinates_x[100];
|
|
|
|
static int saved_coordinates_y[100];
|
|
|
|
|
2021-02-01 23:30:15 +00:00
|
|
|
int get_saved_coordinates_x(int i) { return saved_coordinates_x[i]; }
|
|
|
|
int get_saved_coordinates_y(int i) { return saved_coordinates_y[i]; }
|
2021-01-29 23:25:58 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static int text_size_updater(char *s, int special_index) {
|
|
|
|
int w = 0;
|
|
|
|
char *p;
|
|
|
|
special_t *current = specials;
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
for (int i = 0; i < special_index; i++) { current = current->next; }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output() == nullptr || !display_output()->graphical()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
/* get string widths and skip specials */
|
|
|
|
p = s;
|
2018-05-12 23:26:31 +00:00
|
|
|
while (*p != 0) {
|
2018-05-12 16:03:00 +00:00
|
|
|
if (*p == SPECIAL_CHAR) {
|
|
|
|
*p = '\0';
|
|
|
|
w += get_string_width(s);
|
|
|
|
*p = SPECIAL_CHAR;
|
|
|
|
|
|
|
|
if (current->type == BAR || current->type == GAUGE ||
|
|
|
|
current->type == GRAPH) {
|
|
|
|
w += current->width;
|
|
|
|
if (current->height > last_font_height) {
|
|
|
|
last_font_height = current->height;
|
|
|
|
last_font_height += font_height();
|
|
|
|
}
|
|
|
|
} else if (current->type == OFFSET) {
|
2018-05-13 18:20:39 +00:00
|
|
|
if (current->arg > 0) { w += current->arg; }
|
2018-05-12 16:03:00 +00:00
|
|
|
} else if (current->type == VOFFSET) {
|
|
|
|
last_font_height += current->arg;
|
|
|
|
} else if (current->type == GOTO) {
|
2018-05-13 18:20:39 +00:00
|
|
|
if (current->arg > cur_x) { w = static_cast<int>(current->arg); }
|
2018-05-12 16:03:00 +00:00
|
|
|
} else if (current->type == TAB) {
|
|
|
|
int start = current->arg;
|
|
|
|
int step = current->width;
|
2011-10-10 18:51:35 +00:00
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if ((step == 0) || step < 0) { step = 10; }
|
2018-05-12 16:03:00 +00:00
|
|
|
w += step - (cur_x - text_start_x - start) % step;
|
|
|
|
} else if (current->type == FONT) {
|
|
|
|
selected_font = current->font_added;
|
|
|
|
if (font_height() > last_font_height) {
|
|
|
|
last_font_height = font_height();
|
|
|
|
}
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
special_index++;
|
|
|
|
current = current->next;
|
|
|
|
s = p + 1;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
w += get_string_width(s);
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (w > text_width) { text_width = w; }
|
2018-10-18 23:14:03 +00:00
|
|
|
int mw = dpi_scale(maximum_width.get(*state));
|
2018-05-13 18:20:39 +00:00
|
|
|
if (text_width > mw && mw > 0) { text_width = mw; }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
text_height += last_font_height;
|
|
|
|
last_font_height = font_height();
|
|
|
|
return special_index;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2023-01-02 23:54:53 +00:00
|
|
|
static inline void set_foreground_color(Colour c) {
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->set_foreground_color(c);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static void draw_string(const char *s) {
|
2018-12-23 00:06:18 +00:00
|
|
|
int i;
|
|
|
|
int i2;
|
|
|
|
int pos;
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-12-22 20:53:34 +00:00
|
|
|
int width_of_s;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
int max = 0;
|
|
|
|
int added;
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (s[0] == '\0') { return; }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
width_of_s = get_string_width(s);
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
|
|
|
if (draw_mode == FG) {
|
|
|
|
for (auto output : display_outputs())
|
|
|
|
if (!output->graphical()) output->draw_string(s, 0);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
int tbs = text_buffer_size.get(*state);
|
|
|
|
memset(tmpstring1, 0, tbs);
|
|
|
|
memset(tmpstring2, 0, tbs);
|
|
|
|
strncpy(tmpstring1, s, tbs - 1);
|
|
|
|
pos = 0;
|
|
|
|
added = 0;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output() && display_output()->graphical()) {
|
2022-09-20 05:25:09 +00:00
|
|
|
max = ((text_width - width_of_s) / std::max(1, get_string_width(" ")));
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
/* This code looks for tabs in the text and coverts them to spaces.
|
|
|
|
* The trick is getting the correct number of spaces, and not going
|
|
|
|
* over the window's size without forcing the window larger. */
|
|
|
|
for (i = 0; i < tbs; i++) {
|
|
|
|
if (tmpstring1[i] == '\t') {
|
|
|
|
i2 = 0;
|
|
|
|
for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
|
|
|
|
/* guard against overrun */
|
2018-12-21 02:20:43 +00:00
|
|
|
tmpstring2[std::min(pos + i2, tbs - 1)] = ' ';
|
2018-05-12 16:03:00 +00:00
|
|
|
added++;
|
|
|
|
}
|
|
|
|
pos += i2;
|
|
|
|
} else {
|
|
|
|
/* guard against overrun */
|
2018-12-21 02:20:43 +00:00
|
|
|
tmpstring2[std::min(pos, tbs - 1)] = tmpstring1[i];
|
2018-05-12 16:03:00 +00:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output() && display_output()->graphical()) {
|
|
|
|
int mw = display_output()->dpi_scale(maximum_width.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
if (text_width == mw) {
|
|
|
|
/* this means the text is probably pushing the limit,
|
|
|
|
* so we'll chop it */
|
|
|
|
while (cur_x + get_string_width(tmpstring2) - text_start_x > mw &&
|
|
|
|
strlen(tmpstring2) > 0) {
|
|
|
|
tmpstring2[strlen(tmpstring2) - 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
s = tmpstring2;
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output() && display_output()->graphical()) {
|
|
|
|
display_output()->draw_string_at(text_offset_x + cur_x,
|
|
|
|
text_offset_y + cur_y, s, strlen(s));
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
cur_x += width_of_s;
|
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
memcpy(tmpstring1, s, tbs);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#if defined(BUILD_MATH) && defined(BUILD_GUI)
|
2019-10-07 02:29:04 +00:00
|
|
|
/// Format \a size as a real followed by closest SI unit, with \a prec number
|
|
|
|
/// of digits after the decimal point.
|
|
|
|
static std::string formatSizeWithUnits(double size, int prec = 1) {
|
|
|
|
int div = 0;
|
|
|
|
double rem = 0;
|
|
|
|
|
|
|
|
while (size >= 1024.0 &&
|
|
|
|
static_cast<size_t>(div) < (sizeof suffixes / sizeof *suffixes)) {
|
|
|
|
rem = fmod(size, 1024.0);
|
|
|
|
div++;
|
|
|
|
size /= 1024.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double size_d = size + rem / 1024.0;
|
|
|
|
|
|
|
|
std::ostringstream result;
|
|
|
|
result.setf(std::ios::fixed, std::ios::floatfield);
|
|
|
|
result.precision(prec);
|
|
|
|
result << size_d;
|
|
|
|
result << " ";
|
|
|
|
|
|
|
|
if (short_units.get(*state)) {
|
|
|
|
result << suffixes[div][0];
|
|
|
|
} else {
|
|
|
|
result << suffixes[div];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.str();
|
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_MATH && BUILD_GUI */
|
2019-10-07 02:29:04 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifndef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
static int cur_x, cur_y; /* current x and y for drawing */
|
2018-12-22 18:26:23 +00:00
|
|
|
(void)cur_y;
|
2016-09-08 15:24:29 +00:00
|
|
|
#endif
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
int font_h = 0;
|
|
|
|
int cur_y_add = 0;
|
2018-10-18 23:14:03 +00:00
|
|
|
int mw = maximum_width.get(*state);
|
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
char *p = s;
|
|
|
|
int orig_special_index = special_index;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output() && display_output()->graphical()) {
|
|
|
|
mw = display_output()->dpi_scale(maximum_width.get(*state));
|
2018-05-12 16:03:00 +00:00
|
|
|
font_h = font_height();
|
|
|
|
cur_y += font_ascent();
|
|
|
|
}
|
|
|
|
cur_x = text_start_x;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
while (*p != 0) {
|
2018-05-12 16:03:00 +00:00
|
|
|
if (*p == SPECIAL_CHAR || last_special_applied > -1) {
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
int w = 0;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
/* draw string before special, unless we're dealing multiline
|
|
|
|
* specials */
|
|
|
|
if (last_special_applied > -1) {
|
|
|
|
special_index = last_special_applied;
|
|
|
|
} else {
|
|
|
|
*p = '\0';
|
|
|
|
draw_string(s);
|
|
|
|
*p = SPECIAL_CHAR;
|
|
|
|
s = p + 1;
|
|
|
|
}
|
|
|
|
/* draw special */
|
|
|
|
special_t *current = specials;
|
2018-05-13 18:20:39 +00:00
|
|
|
for (int i = 0; i < special_index; i++) { current = current->next; }
|
2018-05-12 16:03:00 +00:00
|
|
|
switch (current->type) {
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-12-08 22:45:17 +00:00
|
|
|
case HORIZONTAL_LINE:
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
2018-12-08 22:45:17 +00:00
|
|
|
int h = current->height;
|
|
|
|
int mid = font_ascent() / 2;
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
w = text_start_x + text_width - cur_x;
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->set_line_style(h, true);
|
|
|
|
display_output()->draw_line(
|
|
|
|
text_offset_x + cur_x, text_offset_y + cur_y - mid / 2,
|
|
|
|
text_offset_x + cur_x + w, text_offset_y + cur_y - mid / 2);
|
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
case STIPPLED_HR:
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
2018-12-08 22:45:17 +00:00
|
|
|
int h = current->height;
|
|
|
|
char tmp_s = current->arg;
|
|
|
|
int mid = font_ascent() / 2;
|
|
|
|
char ss[2] = {tmp_s, tmp_s};
|
|
|
|
|
|
|
|
w = text_start_x + text_width - cur_x - 1;
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->set_line_style(h, false);
|
|
|
|
display_output()->set_dashes(ss);
|
|
|
|
display_output()->draw_line(
|
|
|
|
text_offset_x + cur_x, text_offset_y + cur_y - mid / 2,
|
|
|
|
text_offset_x + cur_x + w, text_offset_x + cur_y - mid / 2);
|
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
case BAR:
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
2018-12-08 22:45:17 +00:00
|
|
|
int h, by;
|
|
|
|
double bar_usage, scale;
|
|
|
|
if (cur_x - text_start_x > mw && mw > 0) { break; }
|
|
|
|
h = current->height;
|
|
|
|
bar_usage = current->arg;
|
|
|
|
scale = current->scale;
|
|
|
|
by = cur_y - (font_ascent() / 2) - 1;
|
|
|
|
|
|
|
|
if (h < font_h) { by -= h / 2 - 1; }
|
|
|
|
w = current->width;
|
|
|
|
if (w == 0) { w = text_start_x + text_width - cur_x - 1; }
|
|
|
|
if (w < 0) { w = 0; }
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->set_line_style(dpi_scale(1), true);
|
2018-12-08 22:45:17 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
display_output()->draw_rect(text_offset_x + cur_x,
|
|
|
|
text_offset_y + by, w, h);
|
|
|
|
display_output()->fill_rect(text_offset_x + cur_x,
|
|
|
|
text_offset_y + by,
|
|
|
|
w * bar_usage / scale, h);
|
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
if (h > cur_y_add && h > font_h) { cur_y_add = h; }
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GAUGE: /* new GAUGE */
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
2018-12-08 22:45:17 +00:00
|
|
|
int h, by = 0;
|
2023-01-02 23:54:53 +00:00
|
|
|
Colour last_colour = current_color;
|
2015-12-11 00:39:59 +00:00
|
|
|
#ifdef BUILD_MATH
|
2018-12-08 22:45:17 +00:00
|
|
|
float angle, px, py;
|
|
|
|
double usage, scale;
|
2015-12-11 00:39:59 +00:00
|
|
|
#endif /* BUILD_MATH */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
if (cur_x - text_start_x > mw && mw > 0) { break; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
h = current->height;
|
|
|
|
by = cur_y - (font_ascent() / 2) - 1;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
if (h < font_h) { by -= h / 2 - 1; }
|
|
|
|
w = current->width;
|
|
|
|
if (w == 0) { w = text_start_x + text_width - cur_x - 1; }
|
|
|
|
if (w < 0) { w = 0; }
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->set_line_style(1, true);
|
|
|
|
display_output()->draw_arc(text_offset_x + cur_x,
|
|
|
|
text_offset_y + by, w, h * 2, 0,
|
|
|
|
180 * 64);
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2015-12-11 00:39:59 +00:00
|
|
|
#ifdef BUILD_MATH
|
2018-12-08 22:45:17 +00:00
|
|
|
usage = current->arg;
|
|
|
|
scale = current->scale;
|
|
|
|
angle = M_PI * usage / scale;
|
|
|
|
px = static_cast<float>(cur_x + (w / 2.)) -
|
|
|
|
static_cast<float>(w / 2.) * cos(angle);
|
|
|
|
py = static_cast<float>(by + (h)) -
|
|
|
|
static_cast<float>(h) * sin(angle);
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->draw_line(text_offset_x + cur_x + (w / 2.),
|
|
|
|
text_offset_y + by + (h),
|
|
|
|
text_offset_x + static_cast<int>(px),
|
|
|
|
text_offset_y + static_cast<int>(py));
|
|
|
|
}
|
|
|
|
|
2015-12-11 00:39:59 +00:00
|
|
|
#endif /* BUILD_MATH */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
if (h > cur_y_add && h > font_h) { cur_y_add = h; }
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
set_foreground_color(last_colour);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
case GRAPH:
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
2018-12-08 22:45:17 +00:00
|
|
|
int h, by, i = 0, j = 0;
|
2023-02-24 13:13:19 +00:00
|
|
|
int colour_idx = 0;
|
2023-01-02 23:54:53 +00:00
|
|
|
Colour last_colour = current_color;
|
2018-12-08 22:45:17 +00:00
|
|
|
if (cur_x - text_start_x > mw && mw > 0) { break; }
|
|
|
|
h = current->height;
|
|
|
|
by = cur_y - (font_ascent() / 2) - 1;
|
|
|
|
|
|
|
|
if (h < font_h) { by -= h / 2 - 1; }
|
|
|
|
w = current->width;
|
|
|
|
if (w == 0) {
|
|
|
|
w = text_start_x + text_width - cur_x - 1;
|
2018-12-21 02:20:43 +00:00
|
|
|
current->graph_width = std::max(w - 1, 0);
|
2018-12-08 22:45:17 +00:00
|
|
|
if (current->graph_width != current->graph_allocated) {
|
|
|
|
w = current->graph_allocated + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (w < 0) { w = 0; }
|
|
|
|
if (draw_graph_borders.get(*state)) {
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->set_line_style(dpi_scale(1), true);
|
|
|
|
display_output()->draw_rect(text_offset_x + cur_x,
|
|
|
|
text_offset_y + by, w, h);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) display_output()->set_line_style(1, true);
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
/* in case we don't have a graph yet */
|
|
|
|
if (current->graph != nullptr) {
|
2023-02-24 13:13:19 +00:00
|
|
|
std::unique_ptr<Colour[]> tmpcolour;
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2023-02-24 13:13:19 +00:00
|
|
|
if (current->colours_set) {
|
2022-10-06 06:08:43 +00:00
|
|
|
auto factory = create_gradient_factory(w, current->last_colour,
|
|
|
|
current->first_colour);
|
|
|
|
tmpcolour = factory->create_gradient();
|
|
|
|
delete factory;
|
2018-12-08 22:45:17 +00:00
|
|
|
}
|
2023-02-24 13:13:19 +00:00
|
|
|
colour_idx = 0;
|
2018-12-08 22:45:17 +00:00
|
|
|
for (i = w - 2; i > -1; i--) {
|
2023-02-24 13:13:19 +00:00
|
|
|
if (current->colours_set) {
|
|
|
|
if (current->tempgrad != 0) {
|
2018-12-08 22:45:17 +00:00
|
|
|
set_foreground_color(tmpcolour[static_cast<int>(
|
|
|
|
static_cast<float>(w - 2) -
|
|
|
|
current->graph[j] * (w - 2) /
|
|
|
|
std::max(static_cast<float>(current->scale),
|
|
|
|
1.0F))]);
|
|
|
|
} else {
|
|
|
|
set_foreground_color(tmpcolour[colour_idx++]);
|
2023-02-24 13:13:19 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
/* this is mugfugly, but it works */
|
2018-10-18 23:14:03 +00:00
|
|
|
if (display_output()) {
|
|
|
|
display_output()->draw_line(
|
|
|
|
text_offset_x + cur_x + i + 1, text_offset_y + by + h,
|
|
|
|
text_offset_x + cur_x + i + 1,
|
|
|
|
text_offset_y +
|
|
|
|
round_to_positive_int(static_cast<double>(by) + h -
|
|
|
|
current->graph[j] * (h - 1) /
|
|
|
|
current->scale));
|
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
++j;
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
if (h > cur_y_add && h > font_h) { cur_y_add = h; }
|
|
|
|
if (show_graph_range.get(*state)) {
|
|
|
|
int tmp_x = cur_x;
|
|
|
|
int tmp_y = cur_y;
|
|
|
|
unsigned short int seconds = active_update_interval() * w;
|
|
|
|
char *tmp_day_str;
|
|
|
|
char *tmp_hour_str;
|
|
|
|
char *tmp_min_str;
|
|
|
|
char *tmp_sec_str;
|
|
|
|
char *tmp_str;
|
|
|
|
unsigned short int timeunits;
|
|
|
|
if (seconds != 0) {
|
|
|
|
timeunits = seconds / 86400;
|
|
|
|
seconds %= 86400;
|
|
|
|
if (timeunits <= 0 ||
|
|
|
|
asprintf(&tmp_day_str, _("%dd"), timeunits) == -1) {
|
|
|
|
tmp_day_str = strdup("");
|
|
|
|
}
|
|
|
|
timeunits = seconds / 3600;
|
|
|
|
seconds %= 3600;
|
|
|
|
if (timeunits <= 0 ||
|
|
|
|
asprintf(&tmp_hour_str, _("%dh"), timeunits) == -1) {
|
|
|
|
tmp_hour_str = strdup("");
|
|
|
|
}
|
|
|
|
timeunits = seconds / 60;
|
|
|
|
seconds %= 60;
|
|
|
|
if (timeunits <= 0 ||
|
|
|
|
asprintf(&tmp_min_str, _("%dm"), timeunits) == -1) {
|
|
|
|
tmp_min_str = strdup("");
|
|
|
|
}
|
|
|
|
if (seconds <= 0 ||
|
|
|
|
asprintf(&tmp_sec_str, _("%ds"), seconds) == -1) {
|
|
|
|
tmp_sec_str = strdup("");
|
|
|
|
}
|
|
|
|
if (asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str,
|
|
|
|
tmp_min_str, tmp_sec_str) == -1) {
|
|
|
|
tmp_str = strdup("");
|
|
|
|
}
|
|
|
|
free(tmp_day_str);
|
|
|
|
free(tmp_hour_str);
|
|
|
|
free(tmp_min_str);
|
|
|
|
free(tmp_sec_str);
|
|
|
|
} else {
|
|
|
|
tmp_str = strdup(
|
|
|
|
_("Range not possible")); // should never happen, but
|
|
|
|
// better safe then sorry
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
|
|
|
|
cur_y += font_h / 2;
|
|
|
|
draw_string(tmp_str);
|
|
|
|
free(tmp_str);
|
|
|
|
cur_x = tmp_x;
|
|
|
|
cur_y = tmp_y;
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2015-12-11 00:39:59 +00:00
|
|
|
#ifdef BUILD_MATH
|
2018-12-08 22:45:17 +00:00
|
|
|
if (show_graph_scale.get(*state) && (current->show_scale == 1)) {
|
|
|
|
int tmp_x = cur_x;
|
|
|
|
int tmp_y = cur_y;
|
|
|
|
cur_x += font_ascent() / 2;
|
|
|
|
cur_y += font_h / 2;
|
2019-10-07 02:29:04 +00:00
|
|
|
std::string tmp_str = formatSizeWithUnits(
|
|
|
|
current->scale_log != 0 ? std::pow(10.0, current->scale)
|
|
|
|
: current->scale);
|
|
|
|
draw_string(tmp_str.c_str());
|
2018-12-08 22:45:17 +00:00
|
|
|
cur_x = tmp_x;
|
|
|
|
cur_y = tmp_y;
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
#endif
|
2018-12-08 22:45:17 +00:00
|
|
|
set_foreground_color(last_colour);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
case FONT:
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
2018-12-08 22:45:17 +00:00
|
|
|
int old = font_ascent();
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
cur_y -= font_ascent();
|
|
|
|
selected_font = current->font_added;
|
|
|
|
set_font();
|
|
|
|
if (cur_y + font_ascent() < cur_y + old) {
|
|
|
|
cur_y += old;
|
|
|
|
} else {
|
|
|
|
cur_y += font_ascent();
|
|
|
|
}
|
|
|
|
font_h = font_height();
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
case FG:
|
2023-02-24 13:43:15 +00:00
|
|
|
if (draw_mode == FG) {
|
|
|
|
set_foreground_color(Colour::from_argb32(current->arg));
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
case BG:
|
2023-02-24 13:43:15 +00:00
|
|
|
if (draw_mode == BG) {
|
|
|
|
set_foreground_color(Colour::from_argb32(current->arg));
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OUTLINE:
|
2023-02-24 13:43:15 +00:00
|
|
|
if (draw_mode == OUTLINE) {
|
|
|
|
set_foreground_color(Colour::from_argb32(current->arg));
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OFFSET:
|
|
|
|
w += current->arg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VOFFSET:
|
|
|
|
cur_y += current->arg;
|
|
|
|
break;
|
|
|
|
|
2021-01-29 23:25:58 +00:00
|
|
|
case SAVE_COORDINATES:
|
2021-02-01 23:30:15 +00:00
|
|
|
saved_coordinates_x[static_cast<int>(current->arg)] =
|
|
|
|
cur_x - text_start_x;
|
|
|
|
saved_coordinates_y[static_cast<int>(current->arg)] =
|
|
|
|
cur_y - text_start_y - last_font_height;
|
2021-01-29 23:25:58 +00:00
|
|
|
break;
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
case TAB: {
|
|
|
|
int start = current->arg;
|
|
|
|
int step = current->width;
|
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if ((step == 0) || step < 0) { step = 10; }
|
2018-05-12 16:03:00 +00:00
|
|
|
w = step - (cur_x - text_start_x - start) % step;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ALIGNR: {
|
|
|
|
/* TODO: add back in "+ window.border_inner_margin" to the end of
|
|
|
|
* this line? */
|
|
|
|
int pos_x = text_start_x + text_width -
|
|
|
|
get_string_width_special(s, special_index);
|
|
|
|
|
|
|
|
/* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
|
|
|
|
"get_string_width(p) %i gap_x %i "
|
|
|
|
"current->arg %i window.border_inner_margin %i "
|
|
|
|
"window.border_width %i\n", pos_x, text_start_x, text_width,
|
|
|
|
cur_x, get_string_width_special(s), gap_x,
|
|
|
|
current->arg, window.border_inner_margin,
|
|
|
|
window.border_width); */
|
2022-11-28 19:23:23 +00:00
|
|
|
cur_x = pos_x - current->arg;
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ALIGNC: {
|
|
|
|
int pos_x = (text_width) / 2 -
|
|
|
|
get_string_width_special(s, special_index) / 2 -
|
|
|
|
(cur_x - text_start_x);
|
|
|
|
/* int pos_x = text_start_x + text_width / 2 -
|
|
|
|
get_string_width_special(s) / 2; */
|
|
|
|
|
|
|
|
/* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
|
|
|
|
"get_string_width(p) %i gap_x %i "
|
|
|
|
"current->arg %i\n", pos_x, text_start_x,
|
|
|
|
text_width, cur_x, get_string_width(s), gap_x,
|
|
|
|
current->arg); */
|
2018-05-13 18:20:39 +00:00
|
|
|
if (pos_x > current->arg) { w = pos_x - current->arg; }
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
case GOTO:
|
|
|
|
if (current->arg >= 0) {
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 23:26:31 +00:00
|
|
|
cur_x = static_cast<int>(current->arg);
|
2018-05-12 16:03:00 +00:00
|
|
|
// make sure shades are 1 pixel to the right of the text
|
2018-05-13 18:20:39 +00:00
|
|
|
if (draw_mode == BG) { cur_x++; }
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-12-02 16:28:28 +00:00
|
|
|
cur_x = static_cast<int>(current->arg);
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->gotox(cur_x);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
cur_x += w;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
if (special_index != last_special_applied) {
|
|
|
|
special_index++;
|
|
|
|
} else {
|
|
|
|
special_index = orig_special_index;
|
|
|
|
last_special_applied = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
cur_y += cur_y_add;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
draw_string(s);
|
2018-10-05 03:46:50 +00:00
|
|
|
for (auto output : display_outputs()) output->line_inner_done();
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output() && display_output()->graphical()) {
|
|
|
|
cur_y += font_descent();
|
|
|
|
}
|
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
return special_index;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static int draw_line(char *s, int special_index) {
|
2018-10-05 03:46:50 +00:00
|
|
|
if (display_output() && display_output()->draw_line_inner_required()) {
|
2018-05-12 16:03:00 +00:00
|
|
|
return draw_each_line_inner(s, special_index, -1);
|
|
|
|
}
|
|
|
|
draw_string(s);
|
|
|
|
UNUSED(special_index);
|
|
|
|
return 0;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
static void draw_text() {
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->begin_draw_text();
|
|
|
|
#ifdef BUILD_GUI
|
|
|
|
// XXX:only works if inside set_display_output()
|
2022-11-28 19:23:23 +00:00
|
|
|
for (auto output : display_outputs()) {
|
2022-12-24 14:44:03 +00:00
|
|
|
if (output && output->graphical()) {
|
|
|
|
cur_y = text_start_y;
|
|
|
|
int bw = dpi_scale(border_width.get(*state));
|
|
|
|
|
|
|
|
/* draw borders */
|
|
|
|
if (draw_borders.get(*state) && bw > 0) {
|
|
|
|
if (stippled_borders.get(*state) != 0) {
|
|
|
|
char ss[2] = {(char)dpi_scale(stippled_borders.get(*state)),
|
|
|
|
(char)dpi_scale(stippled_borders.get(*state))};
|
|
|
|
output->set_line_style(bw, false);
|
|
|
|
output->set_dashes(ss);
|
|
|
|
} else {
|
|
|
|
output->set_line_style(bw, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset = dpi_scale(border_inner_margin.get(*state)) + bw;
|
|
|
|
output->draw_rect(text_offset_x + text_start_x - offset,
|
|
|
|
text_offset_y + text_start_y - offset,
|
|
|
|
text_width + 2 * offset, text_height + 2 * offset);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-24 14:44:03 +00:00
|
|
|
/* draw text */
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2022-11-28 19:23:23 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
setup_fonts();
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
for_each_line(text_buffer, draw_line);
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->end_draw_text();
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
void draw_stuff() {
|
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
text_offset_x = text_offset_y = 0;
|
2010-01-10 23:35:22 +00:00
|
|
|
#ifdef BUILD_IMLIB2
|
2018-05-12 16:03:00 +00:00
|
|
|
cimlib_render(text_start_x, text_start_y, window.width, window.height);
|
2010-01-10 23:35:22 +00:00
|
|
|
#endif /* BUILD_IMLIB2 */
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-10-19 00:58:38 +00:00
|
|
|
for (auto output : display_outputs()) output->begin_draw_stuff();
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
llua_draw_pre_hook();
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) {
|
|
|
|
if (!output->graphical()) continue;
|
|
|
|
// XXX: we assume a single graphical display
|
|
|
|
set_display_output(output);
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
selected_font = 0;
|
|
|
|
if (draw_shades.get(*state) && !draw_outline.get(*state)) {
|
|
|
|
text_offset_x = text_offset_y = 1;
|
|
|
|
set_foreground_color(default_shade_color.get(*state));
|
|
|
|
draw_mode = BG;
|
|
|
|
draw_text();
|
|
|
|
text_offset_x = text_offset_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw_outline.get(*state)) {
|
|
|
|
selected_font = 0;
|
|
|
|
|
|
|
|
for (text_offset_x = -1; text_offset_x < 2; text_offset_x++) {
|
|
|
|
for (text_offset_y = -1; text_offset_y < 2; text_offset_y++) {
|
2018-05-13 18:20:39 +00:00
|
|
|
if (text_offset_x == 0 && text_offset_y == 0) { continue; }
|
2018-05-12 16:03:00 +00:00
|
|
|
set_foreground_color(default_outline_color.get(*state));
|
|
|
|
draw_mode = OUTLINE;
|
|
|
|
draw_text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
text_offset_x = text_offset_y = 0;
|
|
|
|
}
|
|
|
|
|
2022-10-01 19:53:32 +00:00
|
|
|
selected_font = 0;
|
2018-05-12 16:03:00 +00:00
|
|
|
set_foreground_color(default_color.get(*state));
|
2018-10-18 23:14:03 +00:00
|
|
|
unset_display_output();
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
draw_mode = FG;
|
|
|
|
draw_text();
|
2018-10-18 23:14:03 +00:00
|
|
|
#if defined(BUILD_GUI)
|
2018-05-12 16:03:00 +00:00
|
|
|
llua_draw_post_hook();
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-10-19 00:58:38 +00:00
|
|
|
for (auto output : display_outputs()) output->end_draw_stuff();
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
int need_to_update;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
/* update_text() generates new text and clears old text area */
|
2018-10-18 23:14:03 +00:00
|
|
|
void update_text() {
|
2010-01-10 23:35:22 +00:00
|
|
|
#ifdef BUILD_IMLIB2
|
2018-05-12 16:03:00 +00:00
|
|
|
cimlib_cleanup();
|
2010-01-10 23:35:22 +00:00
|
|
|
#endif /* BUILD_IMLIB2 */
|
2018-05-12 16:03:00 +00:00
|
|
|
generate_text();
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
for (auto output : display_outputs()) {
|
|
|
|
if (output->graphical()) output->clear_text(1);
|
|
|
|
}
|
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
need_to_update = 1;
|
|
|
|
llua_update_info(&info, active_update_interval());
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2013-08-18 18:50:17 +00:00
|
|
|
int inotify_fd = -1;
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
template <typename Out>
|
2018-08-04 20:35:04 +00:00
|
|
|
void split(const std::string &s, char delim, Out result) {
|
2018-12-08 22:45:17 +00:00
|
|
|
std::stringstream ss(s);
|
|
|
|
std::string item;
|
|
|
|
while (std::getline(ss, item, delim)) { *(result++) = item; }
|
2018-08-04 20:35:04 +00:00
|
|
|
}
|
2018-12-08 22:45:17 +00:00
|
|
|
std::vector<std::string> split(const std::string &s, char delim) {
|
|
|
|
std::vector<std::string> elems;
|
|
|
|
split(s, delim, std::back_inserter(elems));
|
|
|
|
return elems;
|
2018-08-04 20:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
bool is_on_battery() { // checks if at least one battery specified in
|
|
|
|
// "detect_battery" is discharging
|
|
|
|
char buf[64];
|
2018-08-04 20:35:04 +00:00
|
|
|
std::vector<std::string> b_items = split(detect_battery.get(*state), ',');
|
|
|
|
|
2018-12-08 22:45:17 +00:00
|
|
|
for (auto const &value : b_items) {
|
2018-08-04 20:35:04 +00:00
|
|
|
get_battery_short_status(buf, 64, value.c_str());
|
|
|
|
if (buf[0] == 'D') { return true; }
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
return false;
|
2018-05-03 12:34:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 21:38:00 +00:00
|
|
|
volatile sig_atomic_t g_sigterm_pending, g_sighup_pending, g_sigusr2_pending;
|
|
|
|
|
|
|
|
void main_loop() {
|
2018-05-12 16:03:00 +00:00
|
|
|
int terminate = 0;
|
2009-08-07 07:24:24 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
2018-05-12 16:03:00 +00:00
|
|
|
sigset_t newmask, oldmask;
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
double t;
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2018-05-12 16:03:00 +00:00
|
|
|
int inotify_config_wd = -1;
|
|
|
|
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
|
|
|
|
#define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16)) + 1
|
|
|
|
char inotify_buff[INOTIFY_BUF_LEN];
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
|
|
|
|
#ifdef SIGNAL_BLOCKING
|
2018-05-12 16:03:00 +00:00
|
|
|
sigemptyset(&newmask);
|
|
|
|
sigaddset(&newmask, SIGINT);
|
|
|
|
sigaddset(&newmask, SIGTERM);
|
|
|
|
sigaddset(&newmask, SIGUSR1);
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
last_update_time = 0.0;
|
|
|
|
next_update_time = get_time() - fmod(get_time(), active_update_interval());
|
|
|
|
info.looped = 0;
|
|
|
|
while (terminate == 0 && (total_run_times.get(*state) == 0 ||
|
|
|
|
info.looped < total_run_times.get(*state))) {
|
2018-05-12 23:26:31 +00:00
|
|
|
if ((update_interval_on_battery.get(*state) != NOBATTERY)) {
|
2018-05-12 16:03:00 +00:00
|
|
|
on_battery = is_on_battery();
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
info.looped++;
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
#ifdef SIGNAL_BLOCKING
|
2018-05-12 16:03:00 +00:00
|
|
|
/* block signals. we will inspect for pending signals later */
|
|
|
|
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("unable to sigprocmask()");
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
if (display_output() && display_output()->graphical()) {
|
|
|
|
t = next_update_time - get_time();
|
|
|
|
display_output()->main_loop_wait(t);
|
2018-05-12 16:03:00 +00:00
|
|
|
} else {
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2018-08-02 15:05:47 +00:00
|
|
|
struct timespec req, rem;
|
|
|
|
auto time_to_sleep = next_update_time - get_time();
|
2019-02-23 19:43:44 +00:00
|
|
|
auto seconds = static_cast<time_t>(std::floor(time_to_sleep));
|
2018-08-02 15:05:47 +00:00
|
|
|
auto nanos = (time_to_sleep - seconds) * 1000000000L;
|
|
|
|
req.tv_sec = seconds;
|
|
|
|
req.tv_nsec = nanos;
|
|
|
|
nanosleep(&req, &rem);
|
2018-05-12 16:03:00 +00:00
|
|
|
update_text();
|
|
|
|
draw_stuff();
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->flush();
|
|
|
|
#ifdef BUILD_GUI
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#endif /* BUILD_GUI */
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
#ifdef SIGNAL_BLOCKING
|
2018-05-12 16:03:00 +00:00
|
|
|
/* unblock signals of interest and let handler fly */
|
2018-05-12 23:26:31 +00:00
|
|
|
if (sigprocmask(SIG_SETMASK, &oldmask, nullptr) < 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("unable to sigprocmask()");
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
if (g_sighup_pending != 0) {
|
|
|
|
g_sighup_pending = 0;
|
2018-08-29 14:11:54 +00:00
|
|
|
NORM_ERR("received SIGUSR1. reloading the config file.");
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
reload_config();
|
|
|
|
}
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
if (g_sigusr2_pending != 0) {
|
|
|
|
g_sigusr2_pending = 0;
|
2018-05-12 16:03:00 +00:00
|
|
|
// refresh view;
|
2020-12-31 08:09:23 +00:00
|
|
|
NORM_ERR("received SIGUSR2. refreshing.");
|
2018-05-12 16:03:00 +00:00
|
|
|
update_text();
|
|
|
|
draw_stuff();
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->flush();
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
if (g_sigterm_pending != 0) {
|
|
|
|
g_sigterm_pending = 0;
|
2018-08-29 14:11:54 +00:00
|
|
|
NORM_ERR("received SIGHUP, SIGINT, or SIGTERM to terminate. bye!");
|
2018-05-12 16:03:00 +00:00
|
|
|
terminate = 1;
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->sigterm_cleanup();
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2018-05-12 16:03:00 +00:00
|
|
|
if (!disable_auto_reload.get(*state) && inotify_fd != -1 &&
|
|
|
|
inotify_config_wd == -1 && !current_config.empty()) {
|
|
|
|
inotify_config_wd =
|
|
|
|
inotify_add_watch(inotify_fd, current_config.c_str(), IN_MODIFY);
|
|
|
|
}
|
|
|
|
if (!disable_auto_reload.get(*state) && inotify_fd != -1 &&
|
|
|
|
inotify_config_wd != -1 && !current_config.empty()) {
|
|
|
|
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;
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
select(inotify_fd + 1, &descriptors, nullptr, NULL, &time_to_wait);
|
2018-05-12 16:03:00 +00:00
|
|
|
if (FD_ISSET(inotify_fd, &descriptors)) {
|
|
|
|
/* process inotify events */
|
|
|
|
len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN - 1);
|
|
|
|
inotify_buff[len] = 0;
|
|
|
|
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.c_str());
|
|
|
|
reload_config();
|
|
|
|
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, current_config.c_str(), IN_MODIFY);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
llua_inotify_query(ev->wd, ev->mask);
|
|
|
|
}
|
|
|
|
idx += INOTIFY_EVENT_SIZE + ev->len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (disable_auto_reload.get(*state) && inotify_fd != -1) {
|
|
|
|
inotify_rm_watch(inotify_fd, inotify_config_wd);
|
|
|
|
close(inotify_fd);
|
|
|
|
inotify_fd = inotify_config_wd = -1;
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
llua_update_info(&info, active_update_interval());
|
|
|
|
}
|
2023-05-05 01:02:35 +00:00
|
|
|
clean_up();
|
2009-08-07 07:24:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2018-05-12 16:03:00 +00:00
|
|
|
if (inotify_fd != -1) {
|
|
|
|
inotify_rm_watch(inotify_fd, inotify_config_wd);
|
|
|
|
close(inotify_fd);
|
|
|
|
inotify_fd = inotify_config_wd = -1;
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
/* reload the config file */
|
2018-05-12 23:26:31 +00:00
|
|
|
static void reload_config() {
|
|
|
|
struct stat sb {};
|
|
|
|
if ((stat(current_config.c_str(), &sb) != 0) ||
|
2018-05-12 16:03:00 +00:00
|
|
|
(!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
|
|
|
|
NORM_ERR(_("Config file '%s' is gone, continuing with config from "
|
|
|
|
"memory.\nIf you recreate this file sent me a SIGUSR1 to tell "
|
|
|
|
"me about it. ( kill -s USR1 %d )"),
|
|
|
|
current_config.c_str(), getpid());
|
|
|
|
return;
|
|
|
|
}
|
2023-05-05 01:02:35 +00:00
|
|
|
clean_up();
|
2018-05-12 23:26:31 +00:00
|
|
|
state = std::make_unique<lua::state>();
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::export_symbols(*state);
|
|
|
|
sleep(1); /* slight pause */
|
|
|
|
initialisation(argc_copy, argv_copy);
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 13:34:39 +00:00
|
|
|
void free_specials(special_t *¤t) {
|
2018-05-12 23:26:31 +00:00
|
|
|
if (current != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
free_specials(current->next);
|
2018-05-13 18:20:39 +00:00
|
|
|
if (current->type == GRAPH) { free(current->graph); }
|
2018-05-12 16:03:00 +00:00
|
|
|
delete current;
|
2018-05-12 23:26:31 +00:00
|
|
|
current = nullptr;
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2019-06-09 21:24:16 +00:00
|
|
|
|
|
|
|
clear_stored_graphs();
|
2010-04-21 16:03:53 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 01:02:35 +00:00
|
|
|
void clean_up(void) {
|
|
|
|
/* free_update_callbacks(); XXX: some new equivalent of this? */
|
2018-05-12 16:03:00 +00:00
|
|
|
free_and_zero(info.cpu_usage);
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : display_outputs()) output->cleanup();
|
|
|
|
conky::shutdown_display_outputs();
|
|
|
|
#ifdef BUILD_GUI
|
2023-05-09 14:14:38 +00:00
|
|
|
if (!display_output() || !display_output()->graphical()) {
|
2018-05-12 16:03:00 +00:00
|
|
|
fonts.clear(); // in set_default_configurations a font is set but not
|
2018-10-18 23:14:03 +00:00
|
|
|
// loaded
|
2023-05-09 14:14:38 +00:00
|
|
|
selected_font = 0;
|
|
|
|
}
|
|
|
|
#endif /* BUILD_GUI */
|
2018-05-12 16:03:00 +00:00
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
if (info.first_process != nullptr) {
|
2018-05-12 16:03:00 +00:00
|
|
|
free_all_processes();
|
2018-05-12 23:26:31 +00:00
|
|
|
info.first_process = nullptr;
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free_text_objects(&global_root_object);
|
2018-12-02 16:28:28 +00:00
|
|
|
delete_block_and_zero(tmpstring1);
|
|
|
|
delete_block_and_zero(tmpstring2);
|
|
|
|
delete_block_and_zero(text_buffer);
|
2018-05-12 16:03:00 +00:00
|
|
|
free_and_zero(global_text);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_PORT_MONITORS
|
2018-05-12 16:03:00 +00:00
|
|
|
tcp_portmon_clear();
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
2018-05-12 16:03:00 +00:00
|
|
|
llua_shutdown_hook();
|
2018-08-12 01:51:21 +00:00
|
|
|
#if defined BUILD_RSS
|
2018-05-12 16:03:00 +00:00
|
|
|
xmlCleanupParser();
|
2010-05-06 15:29:09 +00:00
|
|
|
#endif
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
free_specials(specials);
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
clear_net_stats();
|
|
|
|
clear_fs_stats();
|
|
|
|
clear_diskio_stats();
|
|
|
|
free_and_zero(global_cpu);
|
2010-03-10 19:01:26 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::cleanup_config_settings(*state);
|
|
|
|
state.reset();
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 23:26:31 +00:00
|
|
|
static void set_default_configurations() {
|
2018-05-12 16:03:00 +00:00
|
|
|
update_uname();
|
|
|
|
info.memmax = 0;
|
|
|
|
top_cpu = 0;
|
|
|
|
top_mem = 0;
|
|
|
|
top_time = 0;
|
2010-01-07 18:14:53 +00:00
|
|
|
#ifdef BUILD_IOSTATS
|
2018-05-12 16:03:00 +00:00
|
|
|
top_io = 0;
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
2018-05-12 16:03:00 +00:00
|
|
|
top_running = 0;
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_XMMS2
|
2018-05-12 23:26:31 +00:00
|
|
|
info.xmms2.artist = nullptr;
|
|
|
|
info.xmms2.album = nullptr;
|
|
|
|
info.xmms2.title = nullptr;
|
|
|
|
info.xmms2.genre = nullptr;
|
|
|
|
info.xmms2.comment = nullptr;
|
|
|
|
info.xmms2.url = nullptr;
|
|
|
|
info.xmms2.status = nullptr;
|
|
|
|
info.xmms2.playlist = nullptr;
|
2010-01-07 02:38:12 +00:00
|
|
|
#endif /* BUILD_XMMS2 */
|
2022-11-28 19:23:23 +00:00
|
|
|
|
|
|
|
/* Enable a single output by default based on what was enabled at build-time */
|
|
|
|
#ifdef BUILD_WAYLAND
|
|
|
|
state->pushboolean(true);
|
|
|
|
out_to_wayland.lua_set(*state);
|
|
|
|
#else
|
|
|
|
#ifdef BUILD_X11
|
2018-05-12 16:03:00 +00:00
|
|
|
state->pushboolean(true);
|
|
|
|
out_to_x.lua_set(*state);
|
2009-08-07 07:24:24 +00:00
|
|
|
#else
|
2022-11-28 19:23:23 +00:00
|
|
|
state->pushboolean(true);
|
2018-05-12 16:03:00 +00:00
|
|
|
out_to_stdout.lua_set(*state);
|
2009-08-07 07:24:24 +00:00
|
|
|
#endif
|
2022-11-28 19:23:23 +00:00
|
|
|
#endif
|
2009-08-07 07:24:24 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
info.users.number = 1;
|
2009-08-07 07:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
void load_config_file() {
|
|
|
|
DBGP(_("reading contents from config file '%s'"), current_config.c_str());
|
2010-09-15 21:37:13 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
lua::state &l = *state;
|
|
|
|
lua::stack_sentry s(l);
|
|
|
|
l.checkstack(2);
|
2010-09-15 21:37:13 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
try {
|
2010-11-14 00:25:11 +00:00
|
|
|
#ifdef BUILD_BUILTIN_CONFIG
|
2018-05-12 23:26:31 +00:00
|
|
|
if (current_config == builtin_config_magic) {
|
2018-05-12 16:03:00 +00:00
|
|
|
l.loadstring(defconfig);
|
2018-05-12 23:26:31 +00:00
|
|
|
} else {
|
2010-11-14 00:25:11 +00:00
|
|
|
#endif
|
2018-05-12 16:03:00 +00:00
|
|
|
l.loadfile(current_config.c_str());
|
2018-08-05 12:40:22 +00:00
|
|
|
#ifdef BUILD_BUILTIN_CONFIG
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-08-05 12:40:22 +00:00
|
|
|
#endif
|
2018-05-12 16:03:00 +00:00
|
|
|
} catch (lua::syntax_error &e) {
|
2010-11-22 22:45:38 +00:00
|
|
|
#define SYNTAX_ERR_READ_CONF "Syntax error (%s) while reading config file. "
|
|
|
|
#ifdef BUILD_OLD_CONFIG
|
2018-05-12 16:03:00 +00:00
|
|
|
NORM_ERR(_(SYNTAX_ERR_READ_CONF), e.what());
|
|
|
|
NORM_ERR(_("Assuming it's in old syntax and attempting conversion."));
|
|
|
|
// the strchr thingy skips the first line (#! /usr/bin/lua)
|
|
|
|
l.loadstring(strchr(convertconf, '\n'));
|
|
|
|
l.pushstring(current_config.c_str());
|
|
|
|
l.call(1, 1);
|
2010-11-22 22:45:38 +00:00
|
|
|
#else
|
2018-12-08 22:45:17 +00:00
|
|
|
char *syntaxerr;
|
2018-12-22 18:16:38 +00:00
|
|
|
if (asprintf(&syntaxerr, _(SYNTAX_ERR_READ_CONF), e.what())) {
|
|
|
|
std::string syntaxerrobj(syntaxerr);
|
|
|
|
free(syntaxerr);
|
|
|
|
throw conky::error(syntaxerrobj);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
l.call(0, 0);
|
|
|
|
|
|
|
|
l.getglobal("conky");
|
|
|
|
l.getfield(-1, "text");
|
|
|
|
l.replace(-2);
|
2018-05-12 23:26:31 +00:00
|
|
|
if (l.type(-1) != lua::TSTRING) {
|
2018-05-12 16:03:00 +00:00
|
|
|
throw conky::error(_("missing text block in configuration"));
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
/* Remove \\-\n. */
|
|
|
|
l.gsub(l.tocstring(-1), "\\\n", "");
|
|
|
|
l.replace(-2);
|
|
|
|
global_text = strdup(l.tocstring(-1));
|
|
|
|
l.pop();
|
2008-06-19 19:59:30 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 13:34:40 +00:00
|
|
|
inline void reset_optind() {
|
2018-05-12 16:03:00 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
|
|
|
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
|
|
|
optind = optreset = 1;
|
2010-02-20 13:34:40 +00:00
|
|
|
#else
|
2018-05-12 16:03:00 +00:00
|
|
|
optind = 0;
|
2010-02-20 13:34:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-02-23 01:58:44 +00:00
|
|
|
void set_current_config() {
|
2018-05-12 16:03:00 +00:00
|
|
|
/* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
|
2018-05-12 23:26:31 +00:00
|
|
|
struct stat s {};
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
if (current_config.empty()) {
|
|
|
|
/* Try to use personal config file first */
|
|
|
|
std::string buf = to_real_path(XDG_CONFIG_FILE);
|
2018-05-13 18:20:39 +00:00
|
|
|
if (stat(buf.c_str(), &s) == 0) { current_config = buf; }
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_config.empty()) {
|
|
|
|
/* Try to use personal config file first */
|
|
|
|
std::string buf = to_real_path(CONFIG_FILE);
|
2018-05-13 18:20:39 +00:00
|
|
|
if (stat(buf.c_str(), &s) == 0) { current_config = buf; }
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to use system config file if personal config does not exist */
|
2018-05-12 23:26:31 +00:00
|
|
|
if (current_config.empty() && (stat(SYSTEM_CONFIG_FILE, &s) == 0)) {
|
2018-05-12 16:03:00 +00:00
|
|
|
current_config = SYSTEM_CONFIG_FILE;
|
2018-05-12 23:26:31 +00:00
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
|
|
|
|
/* No readable config found */
|
|
|
|
if (current_config.empty()) {
|
2010-09-12 12:01:34 +00:00
|
|
|
#define NOCFGFILEFOUND "no personal or system-wide config file found"
|
2010-02-23 01:58:44 +00:00
|
|
|
#ifdef BUILD_BUILTIN_CONFIG
|
2018-05-12 16:03:00 +00:00
|
|
|
current_config = builtin_config_magic;
|
|
|
|
NORM_ERR(NOCFGFILEFOUND ", using builtin default");
|
2010-02-23 01:58:44 +00:00
|
|
|
#else
|
2018-05-12 16:03:00 +00:00
|
|
|
throw conky::error(NOCFGFILEFOUND);
|
2010-09-12 12:01:34 +00:00
|
|
|
#endif
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2010-09-12 12:01:34 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
// "-" stands for "read from stdin"
|
2018-05-13 18:20:39 +00:00
|
|
|
if (current_config == "-") { current_config = "/dev/stdin"; }
|
2010-02-23 01:58:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 21:38:00 +00:00
|
|
|
/* : means that character before that takes an argument */
|
|
|
|
const char *getopt_string =
|
|
|
|
"vVqdDSs:t:u:i:hc:p:"
|
|
|
|
#ifdef BUILD_X11
|
|
|
|
"x:y:w:a:X:m:f:"
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
"o"
|
|
|
|
#endif
|
|
|
|
"b"
|
|
|
|
#endif /* BUILD_X11 */
|
|
|
|
#ifdef BUILD_BUILTIN_CONFIG
|
|
|
|
"C"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
const struct option longopts[] = {
|
|
|
|
{"help", 0, nullptr, 'h'}, {"version", 0, nullptr, 'V'},
|
|
|
|
{"quiet", 0, nullptr, 'q'}, {"debug", 0, nullptr, 'D'},
|
|
|
|
{"config", 1, nullptr, 'c'},
|
|
|
|
#ifdef BUILD_BUILTIN_CONFIG
|
|
|
|
{"print-config", 0, nullptr, 'C'},
|
|
|
|
#endif
|
|
|
|
{"daemonize", 0, nullptr, 'd'},
|
|
|
|
#ifdef BUILD_X11
|
|
|
|
{"alignment", 1, nullptr, 'a'}, {"display", 1, nullptr, 'X'},
|
|
|
|
{"xinerama-head", 1, nullptr, 'm'}, {"font", 1, nullptr, 'f'},
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
{"own-window", 0, nullptr, 'o'},
|
|
|
|
#endif
|
|
|
|
{"double-buffer", 0, nullptr, 'b'}, {"window-id", 1, nullptr, 'w'},
|
|
|
|
#endif /* BUILD_X11 */
|
|
|
|
{"text", 1, nullptr, 't'}, {"interval", 1, nullptr, 'u'},
|
|
|
|
{"pause", 1, nullptr, 'p'}, {nullptr, 0, nullptr, 0}};
|
|
|
|
|
|
|
|
void setup_inotify() {
|
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
// the file descriptor will be automatically closed on exit
|
|
|
|
inotify_fd = inotify_init();
|
|
|
|
if (inotify_fd != -1) {
|
|
|
|
fcntl(inotify_fd, F_SETFL, fcntl(inotify_fd, F_GETFL) | O_NONBLOCK);
|
|
|
|
|
|
|
|
fcntl(inotify_fd, F_SETFD, fcntl(inotify_fd, F_GETFD) | FD_CLOEXEC);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
}
|
2009-08-07 07:24:24 +00:00
|
|
|
void initialisation(int argc, char **argv) {
|
2018-05-12 23:26:31 +00:00
|
|
|
struct sigaction act {
|
|
|
|
}, oact{};
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
clear_net_stats();
|
|
|
|
set_default_configurations();
|
2010-02-20 01:25:38 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
set_current_config();
|
|
|
|
load_config_file();
|
2007-10-23 21:52:11 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
/* handle other command line arguments */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
reset_optind();
|
2006-03-22 19:27:31 +00:00
|
|
|
|
2007-12-31 00:00:35 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2018-05-12 16:03:00 +00:00
|
|
|
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
|
2018-05-12 23:26:31 +00:00
|
|
|
"kvm_open")) == nullptr) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("cannot read kvm");
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
2006-03-22 19:27:31 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
while (1) {
|
2018-05-12 23:26:31 +00:00
|
|
|
int c = getopt_long(argc, argv, getopt_string, longopts, nullptr);
|
2018-05-12 16:03:00 +00:00
|
|
|
int startup_pause;
|
|
|
|
char *conv_end;
|
2008-01-06 01:35:14 +00:00
|
|
|
|
2018-05-13 18:20:39 +00:00
|
|
|
if (c == -1) { break; }
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
state->pushboolean(true);
|
|
|
|
fork_to_background.lua_set(*state);
|
|
|
|
break;
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_X11
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'f':
|
|
|
|
state->pushstring(optarg);
|
|
|
|
font.lua_set(*state);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
state->pushstring(optarg);
|
|
|
|
text_alignment.lua_set(*state);
|
|
|
|
break;
|
2018-08-16 22:40:34 +00:00
|
|
|
case 'm':
|
|
|
|
state->pushinteger(strtol(optarg, &conv_end, 10));
|
|
|
|
if (*conv_end != 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("'%s' is a wrong xinerama-head index", optarg);
|
2018-08-16 22:40:34 +00:00
|
|
|
}
|
|
|
|
head_index.lua_set(*state);
|
|
|
|
break;
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'X':
|
|
|
|
state->pushstring(optarg);
|
|
|
|
display_name.lua_set(*state);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'o':
|
|
|
|
state->pushboolean(true);
|
|
|
|
own_window.lua_set(*state);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_XDBE
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'b':
|
|
|
|
state->pushboolean(true);
|
|
|
|
use_xdbe.lua_set(*state);
|
|
|
|
break;
|
2012-04-11 16:06:47 +00:00
|
|
|
#else
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'b':
|
|
|
|
state->pushboolean(true);
|
|
|
|
use_xpmdb.lua_set(*state);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2010-01-07 02:38:12 +00:00
|
|
|
#endif /* BUILD_X11 */
|
2018-05-12 16:03:00 +00:00
|
|
|
case 't':
|
|
|
|
free_and_zero(global_text);
|
|
|
|
global_text = strndup(optarg, max_user_text.get(*state));
|
|
|
|
convert_escapes(global_text);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
2018-10-18 23:14:03 +00:00
|
|
|
state->pushinteger(dpi_scale(strtol(optarg, &conv_end, 10)));
|
2018-05-12 16:03:00 +00:00
|
|
|
if (*conv_end != 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("'%s' is a wrong update-interval", optarg);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
update_interval.lua_set(*state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
state->pushinteger(strtol(optarg, &conv_end, 10));
|
|
|
|
if (*conv_end != 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("'%s' is a wrong number of update-times", optarg);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
total_run_times.lua_set(*state);
|
|
|
|
break;
|
2010-01-07 02:38:12 +00:00
|
|
|
#ifdef BUILD_X11
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'x':
|
|
|
|
state->pushinteger(strtol(optarg, &conv_end, 10));
|
|
|
|
if (*conv_end != 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("'%s' is a wrong value for the X-position", optarg);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
gap_x.lua_set(*state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y':
|
|
|
|
state->pushinteger(strtol(optarg, &conv_end, 10));
|
|
|
|
if (*conv_end != 0) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("'%s' is a wrong value for the Y-position", optarg);
|
2018-05-12 16:03:00 +00:00
|
|
|
}
|
|
|
|
gap_y.lua_set(*state);
|
|
|
|
break;
|
2010-01-07 02:38:12 +00:00
|
|
|
#endif /* BUILD_X11 */
|
2018-05-12 16:03:00 +00:00
|
|
|
case 'p':
|
2018-05-12 23:26:31 +00:00
|
|
|
if (first_pass != 0) {
|
2022-09-25 11:09:49 +00:00
|
|
|
startup_pause = strtol(optarg, nullptr, 10);
|
2018-05-12 16:03:00 +00:00
|
|
|
sleep(startup_pause);
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
case '?':
|
|
|
|
throw unknown_arg_throw();
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 21:37:13 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
conky::set_config_settings(*state);
|
2010-10-31 17:17:22 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
2022-10-13 00:13:23 +00:00
|
|
|
if (display_output() && display_output()->graphical()) {
|
|
|
|
current_text_color = default_color.get(*state);
|
|
|
|
}
|
2018-05-12 16:03:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* generate text and get initial size */
|
|
|
|
extract_variable_text(global_text);
|
|
|
|
free_and_zero(global_text);
|
|
|
|
/* fork */
|
2018-05-12 23:26:31 +00:00
|
|
|
if (fork_to_background.get(*state) && (first_pass != 0)) {
|
2018-05-12 16:03:00 +00:00
|
|
|
int pid = fork();
|
|
|
|
|
|
|
|
switch (pid) {
|
|
|
|
case -1:
|
|
|
|
NORM_ERR(PACKAGE_NAME ": couldn't fork() to background: %s",
|
|
|
|
strerror(errno));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* child process */
|
|
|
|
usleep(25000);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* parent process */
|
|
|
|
fprintf(stderr, PACKAGE_NAME ": forked to background, pid is %d\n",
|
|
|
|
pid);
|
|
|
|
fflush(stderr);
|
|
|
|
throw fork_throw();
|
|
|
|
}
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2018-12-02 16:28:28 +00:00
|
|
|
text_buffer = new char[max_user_text.get(*state)];
|
2018-05-12 16:03:00 +00:00
|
|
|
memset(text_buffer, 0, max_user_text.get(*state));
|
2018-12-08 22:45:17 +00:00
|
|
|
tmpstring1 = new char[text_buffer_size.get(*state)];
|
2018-05-12 16:03:00 +00:00
|
|
|
memset(tmpstring1, 0, text_buffer_size.get(*state));
|
2018-12-08 22:45:17 +00:00
|
|
|
tmpstring2 = new char[text_buffer_size.get(*state)];
|
2018-05-12 16:03:00 +00:00
|
|
|
memset(tmpstring2, 0, text_buffer_size.get(*state));
|
2008-03-19 22:28:23 +00:00
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
if (!conky::initialize_display_outputs()) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR("initialize_display_outputs() failed.");
|
2018-10-05 01:48:59 +00:00
|
|
|
}
|
2018-10-18 23:14:03 +00:00
|
|
|
#ifdef BUILD_GUI
|
|
|
|
/* setup lua window globals */
|
|
|
|
llua_setup_window_table(text_start_x, text_start_y, text_width, text_height);
|
|
|
|
#endif /* BUILD_GUI */
|
2018-10-05 01:48:59 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
llua_setup_info(&info, active_update_interval());
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
/* Set signal handlers */
|
|
|
|
act.sa_handler = signal_handler;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
2005-11-24 02:18:42 +00:00
|
|
|
#ifdef SA_RESTART
|
2018-05-12 16:03:00 +00:00
|
|
|
act.sa_flags |= SA_RESTART;
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
if (sigaction(SIGINT, &act, &oact) < 0 ||
|
|
|
|
sigaction(SIGALRM, &act, &oact) < 0 ||
|
|
|
|
sigaction(SIGUSR1, &act, &oact) < 0 ||
|
|
|
|
sigaction(SIGUSR2, &act, &oact) < 0 ||
|
|
|
|
sigaction(SIGHUP, &act, &oact) < 0 ||
|
|
|
|
sigaction(SIGTERM, &act, &oact) < 0) {
|
|
|
|
NORM_ERR("error setting signal handler: %s", strerror(errno));
|
|
|
|
}
|
2005-11-01 06:51:48 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
llua_startup_hook();
|
2009-07-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
static void signal_handler(int sig) {
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
switch (sig) {
|
2018-08-29 14:11:54 +00:00
|
|
|
case SIGHUP:
|
2018-05-12 16:03:00 +00:00
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
2018-05-12 23:26:31 +00:00
|
|
|
g_sigterm_pending = 1;
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
case SIGUSR1:
|
2018-05-12 23:26:31 +00:00
|
|
|
g_sighup_pending = 1;
|
2018-05-12 16:03:00 +00:00
|
|
|
break;
|
|
|
|
case SIGUSR2:
|
2018-05-12 23:26:31 +00:00
|
|
|
g_sigusr2_pending = 1;
|
2018-05-12 16:03:00 +00:00
|
|
|
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.
|
|
|
|
* We cannot print debug messages from a sighandler, so simply ignore.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2005-11-01 06:51:48 +00:00
|
|
|
}
|