From fe27753929be0a6cd96015fb099597d989d85d7c Mon Sep 17 00:00:00 2001 From: bi4k8 Date: Sun, 5 Feb 2023 19:38:20 +0000 Subject: [PATCH] move color settings to their own file these settings are used for GUI builds as well as ncurses builds, and if we support colors in console and HTTP output, will be used there too colors really are essential to what Conky does, even if some outputs don't support them, so it makes sense to build support for them unconditionally --- src/CMakeLists.txt | 9 +++++-- src/colour-settings.cc | 42 +++++++++++++++++++++++++++++ src/colour-settings.h | 60 ++++++++++++++++++++++++++++++++++++++++++ src/colours.cc | 7 ----- src/core.cc | 1 + src/display-ncurses.cc | 1 - src/gui.cc | 22 +++------------- src/gui.h | 25 +----------------- 8 files changed, 114 insertions(+), 53 deletions(-) create mode 100644 src/colour-settings.cc create mode 100644 src/colour-settings.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b09a847a..1dcf9257 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,6 +48,8 @@ set(conky_sources ${conky_sources} c++wrap.cc c++wrap.hh + colour-settings.cc + colour-settings.h colours.cc colours.h combine.cc @@ -131,7 +133,10 @@ set(conky_sources update-cb.cc update-cb.hh logging.h - semaphore.hh) + semaphore.hh + x11-color.cc + x11-color.h + ) # Platform specific sources if(OS_LINUX) @@ -244,7 +249,7 @@ if(BUILD_X11) endif(BUILD_X11) if(BUILD_GUI) - set(gui fonts.cc fonts.h gui.cc gui.h x11-color.cc x11-color.h) + set(gui fonts.cc fonts.h gui.cc gui.h) set(optional_sources ${optional_sources} ${gui}) endif(BUILD_GUI) diff --git a/src/colour-settings.cc b/src/colour-settings.cc new file mode 100644 index 00000000..c6d58f7a --- /dev/null +++ b/src/colour-settings.cc @@ -0,0 +1,42 @@ +/* + * + * Conky, a system monitor, based on torsmo + * + * Please see COPYING for details + * + * Copyright (c) 2005-2021 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 . + * + */ + +#include + +#include "colour-settings.h" + +namespace priv { +void colour_setting::lua_setter(lua::state &l, bool init) { + lua::stack_sentry s(l, -2); + Base::lua_setter(l, init); + ++s; +} +} // namespace priv + +priv::colour_setting color[COLORS_CUSTOM] = {{"color0", white_argb32}, {"color1", white_argb32}, + {"color2", white_argb32}, {"color3", white_argb32}, + {"color4", white_argb32}, {"color5", white_argb32}, + {"color6", white_argb32}, {"color7", white_argb32}, + {"color8", white_argb32}, {"color9", white_argb32}}; +priv::colour_setting default_color("default_color", white_argb32); diff --git a/src/colour-settings.h b/src/colour-settings.h new file mode 100644 index 00000000..bbed97db --- /dev/null +++ b/src/colour-settings.h @@ -0,0 +1,60 @@ +/* + * + * Conky, a system monitor, based on torsmo + * + * Please see COPYING for details + * + * Copyright (c) 2005-2021 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 . + * + */ +#pragma once + +#include "config.h" +#include "colours.h" +#include "setting.hh" + +namespace priv { +struct colour_traits { + static const lua::Type type = lua::TSTRING; + typedef Colour Type; + + static inline std::pair convert(lua::state &l, int index, + const std::string &) { + return {parse_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_, Colour::from_argb32(default_value_), true) {} +}; +} // namespace priv + +#define COLORS_CUSTOM 10 + +extern priv::colour_setting color[COLORS_CUSTOM]; +extern priv::colour_setting default_color; + +const unsigned long white_argb32 = 0xffffffff; +const unsigned long black_argb32 = 0xff000000; diff --git a/src/colours.cc b/src/colours.cc index 8f3011c1..aa62f499 100644 --- a/src/colours.cc +++ b/src/colours.cc @@ -32,12 +32,7 @@ #ifdef BUILD_X11 #include "x11.h" #endif /*BUILD_X11*/ -#ifdef BUILD_GUI #include "x11-color.h" -#endif /*BUILD_GUI*/ -#ifdef BUILD_NCURSES -#include -#endif /*BUILD_NCURSES*/ /* precalculated: 31/255, and 63/255 */ #define CONST_8_TO_5_BITS 0.12156862745098 @@ -90,7 +85,6 @@ unsigned int adjust_colours(unsigned int colour) { return colour; } -#ifdef BUILD_GUI static int hex_nibble_value(char c) { if (c >= '0' && c <= '9') { return c - '0'; @@ -150,4 +144,3 @@ err: Colour parse_color(const std::string &colour) { return parse_color(colour.c_str()); } -#endif /*BUILD_GUI*/ diff --git a/src/core.cc b/src/core.cc index ebf39573..fa0e799a 100644 --- a/src/core.cc +++ b/src/core.cc @@ -33,6 +33,7 @@ #include "bsdapm.h" #include "build.h" #include "colours.h" +#include "colour-settings.h" #include "combine.h" #include "diskio.h" #include "entropy.h" diff --git a/src/display-ncurses.cc b/src/display-ncurses.cc index 3b47fbbf..74faf2c2 100644 --- a/src/display-ncurses.cc +++ b/src/display-ncurses.cc @@ -63,7 +63,6 @@ extern void init_ncurses_output() {} #ifdef BUILD_NCURSES #define COLORS_BUILTIN 8 -#define COLORS_CUSTOM 10 Colour ncurses_colors[COLORS_BUILTIN + COLORS_CUSTOM] = { {0x00, 0x00, 0x00, 0xff}, // BLACK diff --git a/src/gui.cc b/src/gui.cc index aacddc41..78b601f7 100644 --- a/src/gui.cc +++ b/src/gui.cc @@ -27,6 +27,7 @@ * */ #include "gui.h" +#include "colour-settings.h" #include "common.h" #include "config.h" #include "conky.h" @@ -104,12 +105,6 @@ void own_window_setting::lua_setter(lua::state &l, bool init) { ++s; } - -void colour_setting::lua_setter(lua::state &l, bool init) { - lua::stack_sentry s(l, -2); - Base::lua_setter(l, init); - ++s; -} } // namespace priv template <> @@ -201,19 +196,8 @@ std::string gethostnamecxx() { conky::simple_config_setting text_alignment("alignment", BOTTOM_LEFT, false); -//Colour white = Colour::argb32(0xffffffff); -//Colour black = Colour::argb32(0xff000000); -unsigned long white = 0xffffffff; -unsigned long black = 0xff000000; - -priv::colour_setting color[10] = {{"color0", white}, {"color1", white}, - {"color2", white}, {"color3", white}, - {"color4", white}, {"color5", white}, - {"color6", white}, {"color7", white}, - {"color8", white}, {"color9", white}}; -priv::colour_setting default_color("default_color", white); -priv::colour_setting default_shade_color("default_shade_color", black); -priv::colour_setting default_outline_color("default_outline_color", black); +priv::colour_setting default_shade_color("default_shade_color", black_argb32); +priv::colour_setting default_outline_color("default_outline_color", black_argb32); conky::range_config_setting border_inner_margin( "border_inner_margin", 0, std::numeric_limits::max(), 3, true); diff --git a/src/gui.h b/src/gui.h index 04a94ed1..5d2d56d6 100644 --- a/src/gui.h +++ b/src/gui.h @@ -31,6 +31,7 @@ #include "colours.h" #include "setting.hh" +#include "colour-settings.h" #if defined(BUILD_ARGB) && defined(OWN_WINDOW) /* true if use_argb_visual=true and argb visual was found*/ @@ -100,33 +101,9 @@ class own_window_setting : public conky::simple_config_setting { public: own_window_setting() : Base("own_window", false, false) {} }; - -struct colour_traits { - static const lua::Type type = lua::TSTRING; - typedef Colour Type; - - static inline std::pair convert(lua::state &l, int index, - const std::string &) { - return {parse_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_, Colour::from_argb32(default_value_), true) {} -}; } // namespace priv extern conky::simple_config_setting head_index; -extern priv::colour_setting color[10]; -extern priv::colour_setting default_color; extern priv::colour_setting default_shade_color; extern priv::colour_setting default_outline_color;