diff --git a/src/conky.cc b/src/conky.cc index 4fad3cab..4d73d8b8 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -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) { diff --git a/src/conky.h b/src/conky.h index b4194a71..ccf2b18b 100644 --- a/src/conky.h +++ b/src/conky.h @@ -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; diff --git a/src/core.cc b/src/core.cc index 7ae72ccf..8edb4b30 100644 --- a/src/core.cc +++ b/src/core.cc @@ -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; diff --git a/src/x11.cc b/src/x11.cc index b562d607..fc2bdab7 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -32,7 +32,6 @@ #include "conky.h" #include "logging.h" #include "common.h" -#include "colours.h" #include "x11.h" #include @@ -99,39 +98,19 @@ namespace priv { l.pop(); } -} -namespace { - struct colour_traits { - static const lua::Type type = lua::TSTRING; + void colour_setting::lua_setter(lua::state &l, bool init) + { + lua::stack_sentry s(l, -2); - static std::pair convert(lua::state &l, int index, const std::string &) - { return {get_x11_color(l.tostring(index)), true}; } - }; + if(not out_to_x.get(l)) { + // ignore if we're not using X + l.replace(-2); + } else + Base::lua_setter(l, init); - class colour_setting: public conky::simple_config_setting { - typedef conky::simple_config_setting Base; - - protected: - virtual void lua_setter(lua::state &l, bool init) - { - lua::stack_sentry s(l, -2); - - if(not out_to_x.get(l)) { - // ignore if we're not using X - l.replace(-2); - } else - Base::lua_setter(l, init); - - ++s; - } - - public: - colour_setting(const std::string &name_, unsigned long default_value_ = 0) - : Base(name_, default_value_, true) - {} - - }; + ++s; + } } template<> @@ -211,6 +190,19 @@ conky::simple_config_setting text_alignment("alignment", NONE, fals conky::simple_config_setting 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 own_window("own_window", false, false); conky::simple_config_setting set_transparent("own_window_transparent", false, false); @@ -224,7 +216,7 @@ conky::simple_config_setting own_window_type("own_window_type", TYP conky::simple_config_setting 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 use_argb_visual("own_window_argb_visual", false, false); diff --git a/src/x11.h b/src/x11.h index e7aba663..af0604aa 100644 --- a/src/x11.h +++ b/src/x11.h @@ -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 + 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 { + typedef conky::simple_config_setting 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 display_name; +extern priv::colour_setting color[10]; #ifdef OWN_WINDOW extern conky::simple_config_setting own_window;