1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-19 19:45:15 +00:00

Make colorN a lua setting

This commit is contained in:
Pavel Labath 2010-03-11 11:28:12 +01:00
parent 68272383fa
commit ac8d4385eb
5 changed files with 59 additions and 168 deletions

View File

@ -379,9 +379,6 @@ static int maximum_width;
static int sensor_device;
#endif
long color0, color1, color2, color3, color4, color5, color6, color7, color8,
color9;
/* maximum size of config TEXT buffer, i.e. below TEXT line. */
unsigned int max_user_text;
@ -2460,16 +2457,6 @@ static void __attribute__((unused)) set_default_configurations_for_x(void)
default_fg_color = WhitePixel(display, screen);
default_bg_color = BlackPixel(display, screen);
default_out_color = BlackPixel(display, screen);
color0 = default_fg_color;
color1 = default_fg_color;
color2 = default_fg_color;
color3 = default_fg_color;
color4 = default_fg_color;
color5 = default_fg_color;
color6 = default_fg_color;
color7 = default_fg_color;
color8 = default_fg_color;
color9 = default_fg_color;
current_text_color = default_fg_color;
}
#endif /* BUILD_X11 */
@ -3259,16 +3246,6 @@ char load_config_file(const char *f)
#endif /* BUILD_X11 */
#endif /* BUILD_LUA */
CONF("color0"){}
CONF("color1"){}
CONF("color2"){}
CONF("color3"){}
CONF("color4"){}
CONF("color5"){}
CONF("color6"){}
CONF("color7"){}
CONF("color8"){}
CONF("color9"){}
CONF("default_color"){}
CONF3("default_shade_color", "default_shadecolor"){}
CONF3("default_outline_color", "default_outlinecolor") {}
@ -3327,106 +3304,6 @@ static void load_config_file_x11(const char *f)
continue;
}
CONF2("color0") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color0 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color1") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color1 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color2") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color2 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color3") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color3 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color4") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color4 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color5") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color5 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color6") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color6 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color7") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color7 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color8") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color8 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("color9") {
// XXX X11_initialisation();
if (x_initialised == YES) {
if (value) {
color9 = get_x11_color(value);
} else {
CONF_ERR;
}
}
}
CONF("default_color") {
// XXX X11_initialisation();
if (x_initialised == YES) {

View File

@ -160,8 +160,6 @@ struct x11_info {
/* 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;
struct conftree {
char* string;

View File

@ -500,47 +500,47 @@ struct text_object *construct_text_object(char *s, const char *arg, long
}
#endif /* BUILD_NCURSES */
obj->callbacks.print = &new_fg;
#ifdef BUILD_X11
END OBJ(color0, 0)
obj->data.l = color0;
obj->data.l = color[0].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color1, 0)
obj->data.l = color1;
obj->data.l = color[1].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color2, 0)
obj->data.l = color2;
obj->data.l = color[2].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color3, 0)
obj->data.l = color3;
obj->data.l = color[3].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color4, 0)
obj->data.l = color4;
obj->data.l = color[4].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color5, 0)
obj->data.l = color5;
obj->data.l = color[5].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color6, 0)
obj->data.l = color6;
obj->data.l = color[6].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color7, 0)
obj->data.l = color7;
obj->data.l = color[7].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color8, 0)
obj->data.l = color8;
obj->data.l = color[8].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color9, 0)
obj->data.l = color9;
obj->data.l = color[9].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
#ifdef BUILD_X11
END OBJ(font, 0)
scan_font(obj, arg);
obj->callbacks.print = &new_font;

View File

@ -32,7 +32,6 @@
#include "conky.h"
#include "logging.h"
#include "common.h"
#include "colours.h"
#include "x11.h"
#include <X11/Xlib.h>
@ -99,21 +98,8 @@ namespace priv {
l.pop();
}
}
namespace {
struct colour_traits {
static const lua::Type type = lua::TSTRING;
static std::pair<unsigned long, bool> convert(lua::state &l, int index, const std::string &)
{ return {get_x11_color(l.tostring(index)), true}; }
};
class colour_setting: public conky::simple_config_setting<unsigned long, colour_traits> {
typedef conky::simple_config_setting<unsigned long, colour_traits> Base;
protected:
virtual void lua_setter(lua::state &l, bool init)
void colour_setting::lua_setter(lua::state &l, bool init)
{
lua::stack_sentry s(l, -2);
@ -125,13 +111,6 @@ namespace {
++s;
}
public:
colour_setting(const std::string &name_, unsigned long default_value_ = 0)
: Base(name_, default_value_, true)
{}
};
}
template<>
@ -211,6 +190,19 @@ conky::simple_config_setting<alignment> text_alignment("alignment", NONE, fals
conky::simple_config_setting<std::string> display_name("display", std::string(), false);
priv::out_to_x_setting out_to_x;
priv::colour_setting color[10] = {
{ "color0", 0xffffff },
{ "color1", 0xffffff },
{ "color2", 0xffffff },
{ "color3", 0xffffff },
{ "color4", 0xffffff },
{ "color5", 0xffffff },
{ "color6", 0xffffff },
{ "color7", 0xffffff },
{ "color8", 0xffffff },
{ "color9", 0xffffff }
};
#ifdef OWN_WINDOW
conky::simple_config_setting<bool> own_window("own_window", false, false);
conky::simple_config_setting<bool> set_transparent("own_window_transparent", false, false);
@ -224,7 +216,7 @@ conky::simple_config_setting<window_type> own_window_type("own_window_type", TYP
conky::simple_config_setting<uint16_t, window_hints_traits>
own_window_hints("own_window_hints", 0, false);
colour_setting background_colour("background_colour", 0);
priv::colour_setting background_colour("background_colour", 0);
#ifdef BUILD_ARGB
conky::simple_config_setting<bool> use_argb_visual("own_window_argb_visual", false, false);

View File

@ -40,6 +40,7 @@
#endif
#include "setting.hh"
#include "colours.h"
#define ATOM(a) XInternAtom(display, #a, False)
@ -157,9 +158,32 @@ namespace priv {
: Base("out_to_x", false, false)
{}
};
struct colour_traits {
static const lua::Type type = lua::TSTRING;
static inline std::pair<unsigned long, bool>
convert(lua::state &l, int index, const std::string &)
{ return {get_x11_color(l.tostring(index)), true}; }
};
class colour_setting: public conky::simple_config_setting<unsigned long, colour_traits> {
typedef conky::simple_config_setting<unsigned long, colour_traits> Base;
protected:
virtual void lua_setter(lua::state &l, bool init);
public:
colour_setting(const std::string &name_, unsigned long default_value_ = 0)
: Base(name_, default_value_, true)
{}
};
}
extern priv::out_to_x_setting out_to_x;
extern conky::simple_config_setting<std::string> display_name;
extern priv::colour_setting color[10];
#ifdef OWN_WINDOW
extern conky::simple_config_setting<bool> own_window;