1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-06-10 11:12:21 +00:00

use ARGB, not RGBA, for Wayland color values

this impacts only colors from which we compute Cairo colors, not the
rendered pixel buffers themselves, which were already and remain
ARGB32.

this makes Wayland and (24-bit) X11 use the same representation of
colors, fixing bugs when both backends were enabled.

we should still eventually switch to a backend-independent color
representation, because there are no guarantees of which pixel format
X11 will use (it isn't alway ARGB32) and backends like ncurses have
their own color representation; in most code we just hope the
unsigned long will be interpreted by the same backend as wrote it.
This commit is contained in:
bi4k8 2023-01-03 00:38:51 +00:00 committed by Brenden Matthews
parent 1c95c6d577
commit 31b4c27abc
2 changed files with 17 additions and 17 deletions

View File

@ -104,14 +104,14 @@ long 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 0x000000ff | ((r & 0xff) << 24) | ((g & 0xff) << 16) |
((b & 0xff) << 8);
return 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
}
if (name[0] == '#') {
name++;
len--;
}
if (len == 6 || len == 8) {
bool skip_alpha = (len == 6);
unsigned char argb[4] = {0xff, 0, 0, 0};
for (size_t i = 0; i + 1 < len; i += 2) {
int nib1 = hex_nibble_value(name[i]);
@ -119,7 +119,7 @@ long manually_get_x11_color(const char *name) {
if (nib1 < 0 || nib2 < 0) { goto err; }
int val = (nib1 << 4) + nib2;
argb[3 - i / 2] = val;
argb[skip_alpha + i / 2] = val;
}
long out;
memcpy(static_cast<void *>(&out), argb, 4);

View File

@ -666,15 +666,15 @@ void display_output_wayland::cleanup() {
}
void display_output_wayland::set_foreground_color(long c) {
#ifdef BUILD_ARGB
current_color = (c & ~0xff) | own_window_argb_value.get(*state);
#else
current_color = c;
#ifdef BUILD_ARGB
uint8_t a = own_window_argb_value.get(*state);
#else
uint8_t a = current_color >> 24;
#endif /* BUILD_ARGB */
uint8_t r = current_color >> 24;
uint8_t g = current_color >> 16;
uint8_t b = current_color >> 8;
uint8_t a = current_color;
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);
@ -707,9 +707,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 >> 24;
uint8_t g = current_color >> 16;
uint8_t b = current_color >> 8;
uint8_t r = current_color >> 16;
uint8_t g = current_color >> 8;
uint8_t b = current_color;
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.);
@ -815,10 +815,10 @@ void display_output_wayland::clear_text(int exposures) {
#endif
}
#endif
uint8_t r = color >> 24;
uint8_t g = color >> 16;
uint8_t b = color >> 8;
uint8_t a = color;
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_operator(window->cr, CAIRO_OPERATOR_SOURCE);
cairo_paint(window->cr);