1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-05 21:07:52 +00:00

Started on breaking up conky.c.

These changes will likely result in breakage, particularly with
different features enabled/disabled.
This commit is contained in:
Brenden Matthews 2009-08-05 16:46:51 -06:00
parent c29301d02a
commit 3f4127080e
10 changed files with 3287 additions and 3064 deletions

View File

@ -150,6 +150,8 @@ conky_SOURCES = \
common.c \
conky.c \
conky.h \
core.c \
core.h \
$(freebsd) \
fs.c \
$(hddtemp) \

File diff suppressed because it is too large Load Diff

View File

@ -169,7 +169,41 @@ struct x11_info {
struct monitor_info monitor;
struct desktop_info desktop;
};
#endif
int get_stippled_borders(void);
#endif /* X11 */
/* defined in conky.c */
extern long default_fg_color, default_bg_color, default_out_color;
extern long color0, color1, color2, color3, color4, color5, color6, color7,
color8, color9;
void set_current_text_color(long colour);
long get_current_text_color(void);
void set_updatereset(int);
int get_updatereset(void);
struct conftree {
char* string;
struct conftree* horz_next;
struct conftree* vert_next;
struct conftree* back;
};
char load_config_file(const char *);
char *get_global_text(void);
extern long global_text_lines;
//adds newstring to to the tree unless you can already see it when travelling back.
//if it's possible to attach it then it returns a pointer to the leaf, else it returns NULL
struct conftree* conftree_add(struct conftree* previous, const char* newstring);
extern struct conftree *currentconffile;
#define MAX_TEMPLATES 10
char **get_templates(void);
enum {
INFO_CPU = 0,
@ -361,16 +395,19 @@ extern unsigned int max_user_text;
/* path to config file */
extern char *current_config;
/* just a wrapper for read_exec() defined in conky.c */
void do_read_exec(const char *data, char *buf, const int size);
#ifdef X11
#define TO_X 1
#endif
#endif /* X11 */
#define TO_STDOUT 2
#define TO_STDERR 4
#define OVERWRITE_FILE 8
#define APPEND_FILE 16
#ifdef NCURSES
#define TO_NCURSES 32
#endif
#endif /* NCURSES */
enum x_initialiser_state {
NO = 0,
YES = 1,

3000
src/core.c Normal file

File diff suppressed because it is too large Load Diff

56
src/core.h Normal file
View File

@ -0,0 +1,56 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
*
* Conky, a system monitor, based on torsmo
*
* 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
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* vim: ts=4 sw=4 noet ai cindent syntax=c
*
*/
#ifndef _CONKY_CORE_H_
#define _CONKY_CORE_H_
#include "conky.h"
struct text_object *construct_text_object(const char *s, const char *arg, long
line, void **ifblock_opaque, void *free_at_crash);
size_t remove_comments(char *string);
int extract_variable_text_internal(struct text_object *retval, const char *const_p);
void free_text_objects(struct text_object *root, int internal);
#ifdef X11
void scan_mixer_bar(const char *arg, int *a, int *w, int *h);
#endif /* X11 */
#ifdef HAVE_ICONV
void set_iconv_converting(char i);
void set_iconv_selected(long i);
void iconv_convert(size_t a, char *buff_in, char *p, size_t p_max_size);
#endif /* HAVE_ICONV */
#endif /* _CONKY_CORE_H_ */

View File

@ -390,17 +390,14 @@ void llua_set_number(const char *key, double value)
lua_setfield(lua_L, -2, key);
}
#ifdef X11
void llua_draw_pre_hook(void)
void llua_set_startup_hook(const char *args)
{
if (!lua_L || !draw_pre_hook) return;
llua_do_call(draw_pre_hook, 0);
startup_hook = strdup(args);
}
void llua_draw_post_hook(void)
void llua_set_shutdown_hook(const char *args)
{
if (!lua_L || !draw_post_hook) return;
llua_do_call(draw_post_hook, 0);
shutdown_hook = strdup(args);
}
void llua_startup_hook(void)
@ -415,6 +412,19 @@ void llua_shutdown_hook(void)
llua_do_call(shutdown_hook, 0);
}
#ifdef X11
void llua_draw_pre_hook(void)
{
if (!lua_L || !draw_pre_hook) return;
llua_do_call(draw_pre_hook, 0);
}
void llua_draw_post_hook(void)
{
if (!lua_L || !draw_post_hook) return;
llua_do_call(draw_post_hook, 0);
}
void llua_set_draw_pre_hook(const char *args)
{
draw_pre_hook = strdup(args);
@ -425,16 +435,6 @@ void llua_set_draw_post_hook(const char *args)
draw_post_hook = strdup(args);
}
void llua_set_startup_hook(const char *args)
{
startup_hook = strdup(args);
}
void llua_set_shutdown_hook(const char *args)
{
shutdown_hook = strdup(args);
}
#ifdef LUA_EXTRAS
void llua_set_userdata(const char *key, const char *type, void *value)
{

View File

@ -51,16 +51,18 @@ void llua_close(void);
void llua_inotify_query(int wd, int mask);
#endif /* HAVE_SYS_INOTIFY_H */
#ifdef X11
void llua_draw_pre_hook(void);
void llua_draw_post_hook(void);
void llua_set_startup_hook(const char *args);
void llua_set_shutdown_hook(const char *args);
void llua_startup_hook(void);
void llua_shutdown_hook(void);
#ifdef X11
void llua_draw_pre_hook(void);
void llua_draw_post_hook(void);
void llua_set_draw_pre_hook(const char *args);
void llua_set_draw_post_hook(const char *args);
void llua_set_startup_hook(const char *args);
void llua_set_shutdown_hook(const char *args);
void llua_setup_window_table(int text_start_x, int text_start_y, int text_width, int text_height);
void llua_update_window_table(int text_start_x, int text_start_y, int text_width, int text_height);

View File

@ -31,6 +31,7 @@
#include "conky.h"
#include "logging.h"
#include "specials.h"
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
@ -210,7 +211,7 @@ int mixer_is_mute(int i)
}
#undef data
#else
#else /* MIXER_IS_ALSA */
int mixer_init(const char *name)
{
unsigned int i;
@ -274,4 +275,22 @@ int mixer_is_mute(int i)
{
return !mixer_get(i);
}
#endif
#endif /* MIXER_IS_ALSA */
#ifdef X11
void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
{
char buf1[64];
int n;
if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
*a = mixer_init(buf1);
scan_bar(arg + n, w, h);
} else {
*a = mixer_init(NULL);
scan_bar(arg, w, h);
}
}
#endif /* X11 */

View File

@ -31,6 +31,7 @@
*/
#include "top.h"
#include "logging.h"
static unsigned long g_time = 0;
static unsigned long long previous_total = 0;
@ -716,3 +717,95 @@ void process_find_top(struct process **cpu, struct process **mem,
if (top_io) sp_acopy(spi_head, io, MAX_SP);
#endif /* IOSTATS */
}
int parse_top_args(const char *s, const char *arg, struct text_object *obj)
{
char buf[64];
int n;
if (obj->data.top.was_parsed) {
return 1;
}
obj->data.top.was_parsed = 1;
if (arg && !obj->data.top.s) {
obj->data.top.s = strndup(arg, text_buffer_size);
}
need_mask |= (1 << INFO_TOP);
if (s[3] == 0) {
obj->type = OBJ_top;
top_cpu = 1;
} else if (strcmp(&s[3], "_mem") == EQUAL) {
obj->type = OBJ_top_mem;
top_mem = 1;
} else if (strcmp(&s[3], "_time") == EQUAL) {
obj->type = OBJ_top_time;
top_time = 1;
#ifdef IOSTATS
} else if (strcmp(&s[3], "_io") == EQUAL) {
obj->type = OBJ_top_io;
top_io = 1;
#endif /* IOSTATS */
} else {
#ifdef IOSTATS
NORM_ERR("Must be top, top_mem, top_time or top_io");
#else /* IOSTATS */
NORM_ERR("Must be top, top_mem or top_time");
#endif /* IOSTATS */
return 0;
}
if (!arg) {
NORM_ERR("top needs arguments");
return 0;
}
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (strcmp(buf, "name") == EQUAL) {
obj->data.top.type = TOP_NAME;
} else if (strcmp(buf, "cpu") == EQUAL) {
obj->data.top.type = TOP_CPU;
} else if (strcmp(buf, "pid") == EQUAL) {
obj->data.top.type = TOP_PID;
} else if (strcmp(buf, "mem") == EQUAL) {
obj->data.top.type = TOP_MEM;
} else if (strcmp(buf, "time") == EQUAL) {
obj->data.top.type = TOP_TIME;
} else if (strcmp(buf, "mem_res") == EQUAL) {
obj->data.top.type = TOP_MEM_RES;
} else if (strcmp(buf, "mem_vsize") == EQUAL) {
obj->data.top.type = TOP_MEM_VSIZE;
#ifdef IOSTATS
} else if (strcmp(buf, "io_read") == EQUAL) {
obj->data.top.type = TOP_READ_BYTES;
} else if (strcmp(buf, "io_write") == EQUAL) {
obj->data.top.type = TOP_WRITE_BYTES;
} else if (strcmp(buf, "io_perc") == EQUAL) {
obj->data.top.type = TOP_IO_PERC;
#endif /* IOSTATS */
} else {
NORM_ERR("invalid type arg for top");
#ifdef IOSTATS
NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, "
"io_read, io_write, io_perc");
#else /* IOSTATS */
NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
#endif /* IOSTATS */
return 0;
}
if (n < 1 || n > 10) {
NORM_ERR("invalid num arg for top. Must be between 1 and 10.");
return 0;
} else {
obj->data.top.num = n - 1;
}
} else {
NORM_ERR("invalid argument count for top");
return 0;
}
return 1;
}

View File

@ -41,6 +41,7 @@
******************************************/
#include "conky.h"
#include "text_object.h"
#define CPU_THRESHHOLD 0 /* threshhold for the cpu diff to appear */
#include <time.h>
#include <dirent.h>
@ -141,4 +142,6 @@ void process_find_top(struct process **, struct process **, struct process **
/* lookup a program by it's name */
struct process *get_process_by_name(const char *);
int parse_top_args(const char *s, const char *arg, struct text_object *obj);
#endif /* _top_h_ */