add Colour type and use it pervasively

This commit is contained in:
bi4k8 2023-01-02 23:54:53 +00:00 committed by Brenden Matthews
parent 7451decef5
commit a72902fa35
17 changed files with 253 additions and 105 deletions

View File

@ -35,6 +35,9 @@
#ifdef BUILD_WAYLAND
#include "x11-color.h"
#endif /*BUILD_WAYLAND*/
#ifdef BUILD_NCURSES
#include <ncurses.h>
#endif /*BUILD_NCURSES*/
/* precalculated: 31/255, and 63/255 */
#define CONST_8_TO_5_BITS 0.12156862745098
@ -100,11 +103,48 @@ static int hex_nibble_value(char c) {
return -1;
}
long manually_get_x11_color(const char *name) {
Colour Colour::from_argb32(uint32_t argb) {
Colour out;
out.alpha = argb >> 24;
out.red = (argb >> 16) % 256;
out.green = (argb >> 8) % 256;
out.blue = argb % 256;
return out;
}
Colour error_colour { 0xff, 0x00, 0x00, 0xff };
#ifdef BUILD_NCURSES
Colour Colour::from_ncurses(int nccolor) {
switch(nccolor) {
case COLOR_WHITE:
return {0xff, 0xff, 0xff, 0xff};
case COLOR_RED:
return {0xff, 0x00, 0x00, 0xff};
case COLOR_GREEN:
return {0x00, 0xff, 0x00, 0xff};
case COLOR_YELLOW:
return {0xff, 0xff, 0x00, 0xff};
case COLOR_BLUE:
return {0x00, 0x00, 0xff, 0xff};
case COLOR_MAGENTA:
return {0xff, 0x00, 0xff, 0xff};
case COLOR_CYAN:
return {0x00, 0xff, 0xff, 0xff};
case COLOR_BLACK:
return {0x00, 0x00, 0x00, 0xff};
default:
return error_colour;
}
}
#endif /*BUILD_NCURSES*/
Colour manually_get_x11_color(const char *name) {
unsigned short r, g, b;
size_t len = strlen(name);
if (OsLookupColor(-1, name, len, &r, &g, &b)) {
return 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
Colour out = {(uint8_t)r, (uint8_t)g, (uint8_t)b, 0xff};
return out;
}
if (name[0] == '#') {
name++;
@ -121,20 +161,26 @@ long manually_get_x11_color(const char *name) {
argb[skip_alpha + i / 2] = val;
}
long out = (argb[0] << 24) | (argb[1] << 16) | (argb[2] << 8) | argb[3];
Colour out;
out.alpha = argb[0];
out.red = argb[1];
out.green = argb[2];
out.blue = argb[3];
return out;
}
err:
NORM_ERR("can't parse X color '%s' (%d)", name, len);
return 0xFF00FF;
return error_colour;
}
#endif /* BUILD_WAYLAND */
long get_x11_color(const char *name) {
Colour get_x11_color(const char *name) {
#ifdef BUILD_X11
#ifdef BUILD_WAYLAND
if (!display) { return manually_get_x11_color(name); }
#endif /*BUILD_WAYLAND*/
if (out_to_x.get(*state)) {
assert(display != nullptr);
XColor color;
@ -151,21 +197,27 @@ long get_x11_color(const char *name) {
if (XParseColor(display, DefaultColormap(display, screen), &newname[0],
&color) == 0) {
NORM_ERR("can't parse X color '%s'", name);
return 0xFF00FF;
return error_colour;
}
}
if (XAllocColor(display, DefaultColormap(display, screen), &color) == 0) {
NORM_ERR("can't allocate X color '%s'", name);
}
return static_cast<long>(color.pixel);
Colour out;
out.red = color.red;
out.green = color.green;
out.blue = color.blue;
out.alpha = 0xff;
return out;
}
#endif /*BUILD_X11*/
#ifdef BUILD_WAYLAND
return manually_get_x11_color(name);
#endif /*BUILD_WAYLAND*/
}
long get_x11_color(const std::string &colour) {
Colour get_x11_color(const std::string &colour) {
return get_x11_color(colour.c_str());
}
#endif /*BUILD_GUI*/

View File

@ -31,11 +31,91 @@
#include <memory>
#include <string>
#include <cassert>
#include <climits>
#ifdef BUILD_X11
#include "x11.h"
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
#include <ncurses.h>
#endif
unsigned int adjust_colours(unsigned int);
long get_x11_color(const std::string &colour);
struct Colour {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
public:
// Express the color as a 32-bit ARGB integer (alpha in MSB).
uint32_t to_argb32(void) {
uint32_t out;
out = alpha << 24 | red << 16 | green << 8 | blue;
return out;
}
// Construct from a 32-bit ARGB integer (alpha in MSB).
static Colour from_argb32(uint32_t argb);
#ifdef BUILD_X11
unsigned long to_x11_color(Display *display, int screen) {
if(display == nullptr) {
/* cannot work if display is not open */
return 0;
}
XColor xcolor;
xcolor.pixel = 0;
xcolor.red = red * 257;
xcolor.green = green * 257;
xcolor.blue = blue * 257;
if (XAllocColor(display, DefaultColormap(display, screen), &xcolor) == 0) {
//NORM_ERR("can't allocate X color");
return 0;
}
return static_cast<unsigned long>(xcolor.pixel);
}
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
static Colour from_ncurses(int nccolor);
// Find the nearest ncurses color.
int to_ncurses() {
int nccolors[] = {
COLOR_WHITE,
COLOR_RED,
COLOR_GREEN,
COLOR_YELLOW,
COLOR_BLUE,
COLOR_MAGENTA,
COLOR_CYAN,
COLOR_BLACK,
};
int mindiff = INT_MAX;
int best_nccolor = nccolors[0];
for (int nccolor : nccolors) {
Colour other = Colour::from_ncurses(nccolor);
int diff = abs(red - other.red) +
abs(green - other.green) +
abs(blue - other.blue);
if (diff < mindiff) {
mindiff = diff;
best_nccolor = nccolor;
}
}
return best_nccolor;
}
#endif /* BUILD_NCURSES */
};
Colour get_x11_color(const std::string &colour);
// XXX: when everyone uses C++ strings, remove this C version
long get_x11_color(const char *);
Colour get_x11_color(const char *);
#endif /* _COLOURS_H */

View File

@ -572,11 +572,11 @@ void human_readable(long long num, char *buf, int size) {
/* global object list root element */
static struct text_object global_root_object;
static long current_text_color;
static Colour current_text_color;
void set_current_text_color(long colour) { current_text_color = colour; }
void set_current_text_color(Colour colour) { current_text_color = colour; }
long get_current_text_color() { return current_text_color; }
Colour get_current_text_color() { return current_text_color; }
static void extract_variable_text(const char *p) {
free_text_objects(&global_root_object);
@ -944,7 +944,7 @@ static int cur_x, cur_y; /* current x and y for drawing */
// FG
static int draw_mode; /* FG, BG or OUTLINE */
#ifdef BUILD_GUI
/*static*/ long current_color;
/*static*/ Colour current_color;
static int saved_coordinates_x[100];
static int saved_coordinates_y[100];
@ -1015,7 +1015,7 @@ static int text_size_updater(char *s, int special_index) {
}
#endif /* BUILD_GUI */
static inline void set_foreground_color(long c) {
static inline void set_foreground_color(Colour c) {
for (auto output : display_outputs()) output->set_foreground_color(c);
}
@ -1233,7 +1233,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
case GAUGE: /* new GAUGE */
if (display_output() && display_output()->graphical()) {
int h, by = 0;
unsigned long last_colour = current_color;
Colour last_colour = current_color;
#ifdef BUILD_MATH
float angle, px, py;
double usage, scale;
@ -1283,8 +1283,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
case GRAPH:
if (display_output() && display_output()->graphical()) {
int h, by, i = 0, j = 0;
int colour_idx = 0;
unsigned long last_colour = current_color;
//int colour_idx = 0;
Colour last_colour = current_color;
if (cur_x - text_start_x > mw && mw > 0) { break; }
h = current->height;
by = cur_y - (font_ascent() / 2) - 1;
@ -1318,10 +1318,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
tmpcolour = factory->create_gradient();
delete factory;
}
colour_idx = 0;
//colour_idx = 0;
for (i = w - 2; i > -1; i--) {
if (current->last_colour != 0 || current->first_colour != 0) {
if (current->tempgrad != 0) {
/*if (current->tempgrad != 0) {
set_foreground_color(tmpcolour[static_cast<int>(
static_cast<float>(w - 2) -
current->graph[j] * (w - 2) /
@ -1329,7 +1329,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
1.0F))]);
} else {
set_foreground_color(tmpcolour[colour_idx++]);
}
}*/
}
/* this is mugfugly, but it works */
if (display_output()) {
@ -1433,16 +1433,16 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
break;
#endif /* BUILD_GUI */
case FG:
if (draw_mode == FG) { set_foreground_color(current->arg); }
if (draw_mode == FG) { set_foreground_color(Colour::from_argb32(current->arg)); }
break;
#ifdef BUILD_GUI
case BG:
if (draw_mode == BG) { set_foreground_color(current->arg); }
if (draw_mode == BG) { set_foreground_color(Colour::from_argb32(current->arg)); }
break;
case OUTLINE:
if (draw_mode == OUTLINE) { set_foreground_color(current->arg); }
if (draw_mode == OUTLINE) { set_foreground_color(Colour::from_argb32(current->arg)); }
break;
case OFFSET:

View File

@ -39,6 +39,7 @@
#include <memory>
#include "common.h" /* at least for struct dns_data */
#include "luamm.hh"
#include "colours.h"
#if defined(HAS_MCHECK_H)
#include <mcheck.h>
@ -303,8 +304,8 @@ extern conky::range_config_setting<char> stippled_borders;
extern conky::simple_config_setting<bool> draw_shades;
extern conky::simple_config_setting<bool> draw_outline;
void set_current_text_color(long colour);
long get_current_text_color(void);
void set_current_text_color(Colour colour);
Colour get_current_text_color(void);
void set_updatereset(int);
int get_updatereset(void);

View File

@ -403,7 +403,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#ifdef BUILD_GUI
if (s[0] == '#') {
obj->data.l = get_x11_color(s);
obj->data.l = get_x11_color(s).to_argb32();
obj->callbacks.print = &new_fg;
} else
#endif /* BUILD_GUI */
@ -751,9 +751,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(color, nullptr)
#ifdef BUILD_GUI
if (out_to_gui(*state)) {
obj->data.l =
arg != nullptr ? get_x11_color(arg) : default_color.get(*state);
set_current_text_color(obj->data.l);
Colour c = arg != nullptr ? get_x11_color(arg) : default_color.get(*state);
obj->data.l = c.to_argb32();
set_current_text_color(c);
}
#endif /* BUILD_GUI */
#ifdef BUILD_NCURSES
@ -776,41 +776,43 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.l = COLOR_BLACK;
}
}
set_current_text_color(obj->data.l);
init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
Colour c = Color::from_ncurses(obj->data.l);
obj->data.l = c.to_argb32();
set_current_text_color(c);
init_pair(c.to_ncurses(), c.to_ncurses(), COLOR_BLACK);
}
#endif /* BUILD_NCURSES */
obj->callbacks.print = &new_fg;
#ifdef BUILD_GUI
END OBJ(color0, nullptr) obj->data.l = color[0].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color0, nullptr) obj->data.l = color[0].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color1, nullptr) obj->data.l = color[1].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color1, nullptr) obj->data.l = color[1].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color2, nullptr) obj->data.l = color[2].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color2, nullptr) obj->data.l = color[2].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color3, nullptr) obj->data.l = color[3].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color3, nullptr) obj->data.l = color[3].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color4, nullptr) obj->data.l = color[4].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color4, nullptr) obj->data.l = color[4].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color5, nullptr) obj->data.l = color[5].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color5, nullptr) obj->data.l = color[5].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color6, nullptr) obj->data.l = color[6].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color6, nullptr) obj->data.l = color[6].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color7, nullptr) obj->data.l = color[7].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color7, nullptr) obj->data.l = color[7].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color8, nullptr) obj->data.l = color[8].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color8, nullptr) obj->data.l = color[8].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(color9, nullptr) obj->data.l = color[9].get(*state);
set_current_text_color(obj->data.l);
END OBJ(color9, nullptr) obj->data.l = color[9].get(*state).to_argb32();
set_current_text_color(Colour::from_argb32(obj->data.l));
obj->callbacks.print = &new_fg;
END OBJ(font, nullptr) scan_font(obj, arg);
obj->callbacks.print = &new_font;
@ -1455,13 +1457,15 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(shadecolor, nullptr)
#ifdef BUILD_GUI
obj->data.l =
arg != nullptr ? get_x11_color(arg) : default_shade_color.get(*state);
(arg != nullptr ? get_x11_color(arg) : default_shade_color.get(*state))
.to_argb32();
obj->callbacks.print = &new_bg;
#endif /* BUILD_GUI */
END OBJ(outlinecolor, nullptr)
#ifdef BUILD_GUI
obj->data.l =
arg != nullptr ? get_x11_color(arg) : default_outline_color.get(*state);
(arg != nullptr ? get_x11_color(arg) : default_outline_color.get(*state))
.to_argb32();
obj->callbacks.print = &new_outline;
#endif /* BUILD_GUI */
END OBJ(stippled_hr, nullptr)

View File

@ -48,7 +48,7 @@ class display_output_http : public display_output_base {
virtual bool shutdown();
// drawing primitives
virtual void set_foreground_color(long) {}
virtual void set_foreground_color(Colour) {}
virtual void begin_draw_text();
virtual void end_draw_text();
virtual void draw_string(const char *, int);

View File

@ -80,8 +80,8 @@ bool display_output_ncurses::initialize() {
bool display_output_ncurses::shutdown() { return false; }
void display_output_ncurses::set_foreground_color(long c) {
attron(COLOR_PAIR(c));
void display_output_ncurses::set_foreground_color(Colour c) {
attron(COLOR_PAIR(c.to_ncurses()));
}
void display_output_ncurses::begin_draw_text() {

View File

@ -27,6 +27,7 @@
#include <string>
#include <type_traits>
#include "colours.h"
#include "display-console.hh"
#include "luamm.hh"
@ -49,7 +50,7 @@ class display_output_ncurses : public display_output_console {
virtual bool draw_line_inner_required() { return true; }
// drawing primitives
virtual void set_foreground_color(long c);
virtual void set_foreground_color(Colour c);
virtual void begin_draw_text();
virtual void end_draw_text();

View File

@ -30,6 +30,7 @@
#include <vector>
#include "luamm.hh"
#include "colours.h"
namespace conky {
@ -84,7 +85,7 @@ class display_output_base {
virtual void cleanup() {}
// drawing primitives
virtual void set_foreground_color(long /*c*/) {}
virtual void set_foreground_color(Colour /*c*/) {}
virtual int calc_text_width(const char *s) { return strlen(s); }

View File

@ -166,7 +166,7 @@ void update_text();
extern int need_to_update;
int get_border_total();
extern conky::range_config_setting<int> maximum_width;
extern long current_color;
extern Colour current_color;
/* for pango_fonts */
struct pango_font {
@ -665,19 +665,17 @@ void display_output_wayland::cleanup() {
free_fonts(utf8_mode.get(*state));
}
void display_output_wayland::set_foreground_color(long c) {
void display_output_wayland::set_foreground_color(Colour c) {
current_color = c;
#ifdef BUILD_ARGB
uint8_t a = own_window_argb_value.get(*state);
#else
uint8_t a = current_color >> 24;
current_color.alpha = own_window_argb_value.get(*state);
#endif /* BUILD_ARGB */
uint8_t r = current_color >> 16;
uint8_t g = current_color >> 8;
uint8_t b = current_color;
if (global_window->cr) {
cairo_set_source_rgba(global_window->cr, r / 255.0, g / 255.0, b / 255.0,
a / 255.0);
cairo_set_source_rgba(global_window->cr,
current_color.red / 255.0,
current_color.green / 255.0,
current_color.blue / 255.0,
current_color.alpha / 255.0);
}
}
@ -707,9 +705,9 @@ void display_output_wayland::draw_string_at(int x, int y, const char *s,
adjust_coords(x, y);
pango_layout_set_text(window->layout, s, strlen(s));
cairo_save(window->cr);
uint8_t r = current_color >> 16;
uint8_t g = current_color >> 8;
uint8_t b = current_color;
uint8_t r = current_color.red;
uint8_t g = current_color.green;
uint8_t b = current_color.blue;
unsigned int a = pango_fonts[selected_font].font_alpha;
cairo_set_source_rgba(global_window->cr, r / 255.0, g / 255.0, b / 255.0,
a / 65535.);
@ -802,24 +800,24 @@ void display_output_wayland::end_draw_stuff() {
void display_output_wayland::clear_text(int exposures) {
struct window *window = global_window;
cairo_save(window->cr);
long color = 0;
Colour color;
#ifdef OWN_WINDOW
color = background_colour.get(*state);
if (set_transparent.get(*state)) {
color &= ~0xff;
color.alpha = 0;
} else {
#ifdef BUILD_ARGB
color |= (own_window_argb_value.get(*state));
color.alpha = own_window_argb_value.get(*state);
#else
color |= 0xff;
color.alpha = 0xff;
#endif
}
#endif
uint8_t a = color >> 24;
uint8_t r = color >> 16;
uint8_t g = color >> 8;
uint8_t b = color;
cairo_set_source_rgba(window->cr, r / 255.0, g / 255.0, b / 255.0, a / 255.);
cairo_set_source_rgba(window->cr,
color.red / 255.0,
color.green / 255.0,
color.blue / 255.0,
color.alpha / 255.0);
cairo_set_operator(window->cr, CAIRO_OPERATOR_SOURCE);
cairo_paint(window->cr);
cairo_restore(window->cr);

View File

@ -27,6 +27,7 @@
#include <string>
#include <type_traits>
#include "colours.h"
#include "display-output.hh"
#include "luamm.hh"
#include "wl.h"
@ -54,7 +55,7 @@ class display_output_wayland : public display_output_base {
virtual void cleanup();
// drawing primitives
virtual void set_foreground_color(long);
virtual void set_foreground_color(Colour);
virtual int calc_text_width(const char *);

View File

@ -52,6 +52,7 @@
#include <unordered_map>
#include "conky.h"
#include "colours.h"
#include "display-x11.hh"
#include "gui.h"
#include "llua.h"
@ -73,7 +74,7 @@ void update_text();
extern int need_to_update;
int get_border_total();
extern conky::range_config_setting<int> maximum_width;
extern long current_color;
extern Colour current_color;
#ifdef BUILD_XFT
static int xft_dpi = -1;
#endif /* BUILD_XFT */
@ -604,17 +605,18 @@ void display_output_x11::cleanup() {
}
}
void display_output_x11::set_foreground_color(long c) {
void display_output_x11::set_foreground_color(Colour c) {
#ifdef BUILD_ARGB
if (have_argb_visual) {
current_color = c | (own_window_argb_value.get(*state) << 24);
current_color = c;
current_color.alpha = own_window_argb_value.get(*state);
} else {
#endif /* BUILD_ARGB */
current_color = c;
#ifdef BUILD_ARGB
}
#endif /* BUILD_ARGB */
XSetForeground(display, window.gc, current_color);
XSetForeground(display, window.gc, current_color.to_x11_color(display, screen));
}
int display_output_x11::calc_text_width(const char *s) {
@ -643,7 +645,7 @@ void display_output_x11::draw_string_at(int x, int y, const char *s, int w) {
XColor c;
XftColor c2;
c.pixel = current_color;
c.pixel = current_color.to_x11_color(display, screen);
// query color on custom colormap
XQueryColor(display, window.colourmap, &c);

View File

@ -53,7 +53,7 @@ class display_output_x11 : public display_output_base {
virtual void cleanup();
// drawing primitives
virtual void set_foreground_color(long);
virtual void set_foreground_color(Colour);
virtual int calc_text_width(const char *);

View File

@ -201,14 +201,19 @@ std::string gethostnamecxx() {
conky::simple_config_setting<alignment> text_alignment("alignment", BOTTOM_LEFT,
false);
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}};
priv::colour_setting default_color("default_color", 0xffffff);
priv::colour_setting default_shade_color("default_shade_color", 0x000000);
priv::colour_setting default_outline_color("default_outline_color", 0x000000);
//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);
conky::range_config_setting<int> border_inner_margin(
"border_inner_margin", 0, std::numeric_limits<int>::max(), 3, true);

View File

@ -103,7 +103,7 @@ class own_window_setting : public conky::simple_config_setting<bool> {
struct colour_traits {
static const lua::Type type = lua::TSTRING;
typedef unsigned long Type;
typedef Colour Type;
static inline std::pair<Type, bool> convert(lua::state &l, int index,
const std::string &) {
@ -112,15 +112,15 @@ struct colour_traits {
};
class colour_setting
: public conky::simple_config_setting<unsigned long, colour_traits> {
typedef conky::simple_config_setting<unsigned long, colour_traits> Base;
: 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_, default_value_, true) {}
: Base(name_, Colour::from_argb32(default_value_), true) {}
};
} // namespace priv

View File

@ -29,6 +29,7 @@
#include <vector>
#include "conky.h"
#include "core.h"
#include "colours.h"
#include "display-output.hh"
#include "logging.h"
#include "specials.h"
@ -81,7 +82,7 @@ struct scroll_data {
int wait;
unsigned int wait_arg;
signed int start;
long resetcolor;
Colour resetcolor;
int direction;
};
@ -322,7 +323,7 @@ void print_scroll(struct text_object *obj, char *p, unsigned int p_max_size) {
#ifdef BUILD_GUI
// reset color when scroll is finished
if (display_output() && display_output()->graphical()) {
new_special(p + strlen(p), FG)->arg = sd->resetcolor;
new_special(p + strlen(p), FG)->arg = sd->resetcolor.to_argb32();
}
#endif
}

View File

@ -399,9 +399,11 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop) {
#ifdef OWN_WINDOW
namespace {
/* helper function for set_transparent_background() */
void do_set_background(Window win, int argb) {
unsigned long colour = background_colour.get(*state) | (argb << 24);
XSetWindowBackground(display, win, colour);
void do_set_background(Window win, uint8_t alpha) {
Colour colour = background_colour.get(*state);
colour.alpha = alpha;
unsigned long xcolor = colour.to_x11_color(display, screen);
XSetWindowBackground(display, win, xcolor);
}
} // namespace