1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 01:57:09 +00:00

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
This commit is contained in:
bi4k8 2023-02-05 19:38:20 +00:00 committed by Brenden Matthews
parent 9b2706fc49
commit fe27753929
8 changed files with 114 additions and 53 deletions

View File

@ -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)

42
src/colour-settings.cc Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#include <config.h>
#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);

60
src/colour-settings.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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<Type, bool> convert(lua::state &l, int index,
const std::string &) {
return {parse_color(l.tostring(index)), true};
}
};
class colour_setting
: public conky::simple_config_setting<Colour, colour_traits> {
typedef conky::simple_config_setting<Colour, 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_, 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;

View File

@ -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 <ncurses.h>
#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*/

View File

@ -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"

View File

@ -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

View File

@ -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<alignment> 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<int> border_inner_margin(
"border_inner_margin", 0, std::numeric_limits<int>::max(), 3, true);

View File

@ -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<bool> {
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<Type, bool> convert(lua::state &l, int index,
const std::string &) {
return {parse_color(l.tostring(index)), true};
}
};
class colour_setting
: public conky::simple_config_setting<Colour, colour_traits> {
typedef conky::simple_config_setting<Colour, 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_, Colour::from_argb32(default_value_), true) {}
};
} // namespace priv
extern conky::simple_config_setting<int> 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;