Parse colors as color_t instead of colorpixel.

With this patch we remove the temporary draw_util_colorpixel_to_color
function we introduced previously by parsing the colors as color_t to
begin with.

relates to #1278
This commit is contained in:
Ingo Bürk 2015-11-16 23:03:39 +01:00
parent fdeb4e0c36
commit a4afd1b642
9 changed files with 45 additions and 55 deletions

View File

@ -50,10 +50,10 @@ struct context {
* *
*/ */
struct Colortriple { struct Colortriple {
uint32_t border; color_t border;
uint32_t background; color_t background;
uint32_t text; color_t text;
uint32_t indicator; color_t indicator;
}; };
/** /**
@ -202,7 +202,7 @@ struct Config {
/* Color codes are stored here */ /* Color codes are stored here */
struct config_client { struct config_client {
uint32_t background; color_t background;
struct Colortriple focused; struct Colortriple focused;
struct Colortriple focused_inactive; struct Colortriple focused_inactive;
struct Colortriple unfocused; struct Colortriple unfocused;

View File

@ -179,7 +179,7 @@ struct deco_render_params {
struct width_height con_rect; struct width_height con_rect;
struct width_height con_window_rect; struct width_height con_window_rect;
Rect con_deco_rect; Rect con_deco_rect;
uint32_t background; color_t background;
layout_t parent_layout; layout_t parent_layout;
bool con_is_leaf; bool con_is_leaf;
}; };

View File

@ -554,8 +554,6 @@ void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface);
*/ */
color_t draw_util_hex_to_color(const char *color); color_t draw_util_hex_to_color(const char *color);
color_t draw_util_colorpixel_to_color(uint32_t colorpixel);
/** /**
* Draw the given text using libi3. * Draw the given text using libi3.
* This function also marks the surface dirty which is needed if other means of * This function also marks the surface dirty which is needed if other means of

View File

@ -99,14 +99,6 @@ color_t draw_util_hex_to_color(const char *color) {
.colorpixel = get_colorpixel(color)}; .colorpixel = get_colorpixel(color)};
} }
color_t draw_util_colorpixel_to_color(uint32_t colorpixel) {
return (color_t){
.red = ((colorpixel >> 16) & 0xFF) / 255.0,
.green = ((colorpixel >> 8) & 0xFF) / 255.0,
.blue = (colorpixel & 0xFF) / 255.0,
.colorpixel = colorpixel};
}
/* /*
* Set the given color as the source color on the surface. * Set the given color as the source color on the surface.
* *

View File

@ -191,13 +191,13 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
/* Initialize default colors */ /* Initialize default colors */
#define INIT_COLOR(x, cborder, cbackground, ctext, cindicator) \ #define INIT_COLOR(x, cborder, cbackground, ctext, cindicator) \
do { \ do { \
x.border = get_colorpixel(cborder); \ x.border = draw_util_hex_to_color(cborder); \
x.background = get_colorpixel(cbackground); \ x.background = draw_util_hex_to_color(cbackground); \
x.text = get_colorpixel(ctext); \ x.text = draw_util_hex_to_color(ctext); \
x.indicator = get_colorpixel(cindicator); \ x.indicator = draw_util_hex_to_color(cindicator); \
} while (0) } while (0)
config.client.background = get_colorpixel("#000000"); config.client.background = draw_util_hex_to_color("#000000");
INIT_COLOR(config.client.focused, "#4c7899", "#285577", "#ffffff", "#2e9ef4"); INIT_COLOR(config.client.focused, "#4c7899", "#285577", "#ffffff", "#2e9ef4");
INIT_COLOR(config.client.focused_inactive, "#333333", "#5f676a", "#ffffff", "#484e50"); INIT_COLOR(config.client.focused_inactive, "#333333", "#5f676a", "#ffffff", "#484e50");
INIT_COLOR(config.client.unfocused, "#333333", "#222222", "#888888", "#292d2e"); INIT_COLOR(config.client.unfocused, "#333333", "#222222", "#888888", "#292d2e");

View File

@ -332,20 +332,20 @@ CFGFUN(popup_during_fullscreen, const char *value) {
CFGFUN(color_single, const char *colorclass, const char *color) { CFGFUN(color_single, const char *colorclass, const char *color) {
/* used for client.background only currently */ /* used for client.background only currently */
config.client.background = get_colorpixel(color); config.client.background = draw_util_hex_to_color(color);
} }
CFGFUN(color, const char *colorclass, const char *border, const char *background, const char *text, const char *indicator) { CFGFUN(color, const char *colorclass, const char *border, const char *background, const char *text, const char *indicator) {
#define APPLY_COLORS(classname) \ #define APPLY_COLORS(classname) \
do { \ do { \
if (strcmp(colorclass, "client." #classname) == 0) { \ if (strcmp(colorclass, "client." #classname) == 0) { \
config.client.classname.border = get_colorpixel(border); \ config.client.classname.border = draw_util_hex_to_color(border); \
config.client.classname.background = get_colorpixel(background); \ config.client.classname.background = draw_util_hex_to_color(background); \
config.client.classname.text = get_colorpixel(text); \ config.client.classname.text = draw_util_hex_to_color(text); \
if (indicator != NULL) { \ if (indicator != NULL) { \
config.client.classname.indicator = get_colorpixel(indicator); \ config.client.classname.indicator = draw_util_hex_to_color(indicator); \
} \ } \
} \ } \
} while (0) } while (0)
APPLY_COLORS(focused_inactive); APPLY_COLORS(focused_inactive);

View File

@ -146,7 +146,7 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
} }
mask = XCB_CW_BACK_PIXEL; mask = XCB_CW_BACK_PIXEL;
values[0] = config.client.focused.border; values[0] = config.client.focused.border.colorpixel;
mask |= XCB_CW_OVERRIDE_REDIRECT; mask |= XCB_CW_OVERRIDE_REDIRECT;
values[1] = 1; values[1] = 1;

View File

@ -125,7 +125,7 @@ void restore_connect(void) {
static void update_placeholder_contents(placeholder_state *state) { static void update_placeholder_contents(placeholder_state *state) {
xcb_change_gc(restore_conn, state->gc, XCB_GC_FOREGROUND, xcb_change_gc(restore_conn, state->gc, XCB_GC_FOREGROUND,
(uint32_t[]){config.client.placeholder.background}); (uint32_t[]){config.client.placeholder.background.colorpixel});
xcb_poly_fill_rectangle(restore_conn, state->pixmap, state->gc, 1, xcb_poly_fill_rectangle(restore_conn, state->pixmap, state->gc, 1,
(xcb_rectangle_t[]){{0, 0, state->rect.width, state->rect.height}}); (xcb_rectangle_t[]){{0, 0, state->rect.width, state->rect.height}});
@ -133,7 +133,7 @@ static void update_placeholder_contents(placeholder_state *state) {
xcb_flush(restore_conn); xcb_flush(restore_conn);
xcb_aux_sync(restore_conn); xcb_aux_sync(restore_conn);
set_font_colors(state->gc, config.client.placeholder.text, config.client.placeholder.background); set_font_colors(state->gc, config.client.placeholder.text.colorpixel, config.client.placeholder.background.colorpixel);
Match *swallows; Match *swallows;
int n = 0; int n = 0;
@ -193,7 +193,7 @@ static void open_placeholder_window(Con *con) {
true, true,
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
(uint32_t[]){ (uint32_t[]){
config.client.placeholder.background, config.client.placeholder.background.colorpixel,
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY,
}); });
/* Make i3 not focus this window. */ /* Make i3 not focus this window. */

38
src/x.c
View File

@ -327,10 +327,10 @@ static void x_draw_decoration_border(Con *con, struct deco_render_params *p) {
deco_diff_r = 0; deco_diff_r = 0;
} }
draw_util_rectangle(conn, &(con->parent->frame_buffer), draw_util_colorpixel_to_color(p->color->border), draw_util_rectangle(conn, &(con->parent->frame_buffer), p->color->border,
dr->x, dr->y, dr->width, 1); dr->x, dr->y, dr->width, 1);
draw_util_rectangle(conn, &(con->parent->frame_buffer), draw_util_colorpixel_to_color(p->color->border), draw_util_rectangle(conn, &(con->parent->frame_buffer), p->color->border,
dr->x + deco_diff_l, dr->y + dr->height - 1, dr->width - (deco_diff_l + deco_diff_r), 1); dr->x + deco_diff_l, dr->y + dr->height - 1, dr->width - (deco_diff_l + deco_diff_r), 1);
} }
@ -343,18 +343,18 @@ static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p
/* Redraw the right border to cut off any text that went past it. /* Redraw the right border to cut off any text that went past it.
* This is necessary when the text was drawn using XCB since cutting text off * This is necessary when the text was drawn using XCB since cutting text off
* automatically does not work there. For pango rendering, this isn't necessary. */ * automatically does not work there. For pango rendering, this isn't necessary. */
draw_util_rectangle(conn, &(con->parent->frame_buffer), draw_util_colorpixel_to_color(p->color->background), draw_util_rectangle(conn, &(con->parent->frame_buffer), p->color->background,
dr->x + dr->width + br.width, dr->y, -br.width, dr->height); dr->x + dr->width + br.width, dr->y, -br.width, dr->height);
/* Draw a 1px separator line before and after every tab, so that tabs can /* Draw a 1px separator line before and after every tab, so that tabs can
* be easily distinguished. */ * be easily distinguished. */
if (con->parent->layout == L_TABBED) { if (con->parent->layout == L_TABBED) {
/* Left side */ /* Left side */
draw_util_rectangle(conn, &(con->parent->frame_buffer), draw_util_colorpixel_to_color(p->color->border), draw_util_rectangle(conn, &(con->parent->frame_buffer), p->color->border,
dr->x, dr->y, 1, dr->height); dr->x, dr->y, 1, dr->height);
/* Right side */ /* Right side */
draw_util_rectangle(conn, &(con->parent->frame_buffer), draw_util_colorpixel_to_color(p->color->border), draw_util_rectangle(conn, &(con->parent->frame_buffer), p->color->border,
dr->x + dr->width - 1, dr->y, 1, dr->height); dr->x + dr->width - 1, dr->y, 1, dr->height);
} }
@ -448,16 +448,16 @@ void x_draw_decoration(Con *con) {
/* 2: draw the client.background, but only for the parts around the window_rect */ /* 2: draw the client.background, but only for the parts around the window_rect */
if (con->window != NULL) { if (con->window != NULL) {
/* top area */ /* top area */
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(config.client.background), draw_util_rectangle(conn, &(con->frame_buffer), config.client.background,
0, 0, r->width, w->y); 0, 0, r->width, w->y);
/* bottom area */ /* bottom area */
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(config.client.background), draw_util_rectangle(conn, &(con->frame_buffer), config.client.background,
0, w->y + w->height, r->width, r->height - (w->y + w->height)); 0, w->y + w->height, r->width, r->height - (w->y + w->height));
/* left area */ /* left area */
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(config.client.background), draw_util_rectangle(conn, &(con->frame_buffer), config.client.background,
0, 0, w->x, r->height); 0, 0, w->x, r->height);
/* right area */ /* right area */
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(config.client.background), draw_util_rectangle(conn, &(con->frame_buffer), config.client.background,
w->x + w->width, 0, r->width - (w->x + w->width), r->height); w->x + w->width, 0, r->width - (w->x + w->width), r->height);
} }
@ -479,20 +479,20 @@ void x_draw_decoration(Con *con) {
* rectangle because some childs are not freely resizable and we want * rectangle because some childs are not freely resizable and we want
* their background color to "shine through". */ * their background color to "shine through". */
if (!(borders_to_hide & ADJ_LEFT_SCREEN_EDGE)) { if (!(borders_to_hide & ADJ_LEFT_SCREEN_EDGE)) {
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(p->color->background), draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
0, 0, br.x, r->height); 0, 0, br.x, r->height);
} }
if (!(borders_to_hide & ADJ_RIGHT_SCREEN_EDGE)) { if (!(borders_to_hide & ADJ_RIGHT_SCREEN_EDGE)) {
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(p->color->background), draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
r->width + (br.width + br.x), 0, -(br.width + br.x), r->height); r->width + (br.width + br.x), 0, -(br.width + br.x), r->height);
} }
if (!(borders_to_hide & ADJ_LOWER_SCREEN_EDGE)) { if (!(borders_to_hide & ADJ_LOWER_SCREEN_EDGE)) {
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(p->color->background), draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y)); br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y));
} }
/* pixel border needs an additional line at the top */ /* pixel border needs an additional line at the top */
if (p->border_style == BS_PIXEL && !(borders_to_hide & ADJ_UPPER_SCREEN_EDGE)) { if (p->border_style == BS_PIXEL && !(borders_to_hide & ADJ_UPPER_SCREEN_EDGE)) {
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(p->color->background), draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
br.x, 0, r->width + br.width, br.y); br.x, 0, r->width + br.width, br.y);
} }
@ -504,10 +504,10 @@ void x_draw_decoration(Con *con) {
TAILQ_PREV(con, nodes_head, nodes) == NULL && TAILQ_PREV(con, nodes_head, nodes) == NULL &&
con->parent->type != CT_FLOATING_CON) { con->parent->type != CT_FLOATING_CON) {
if (p->parent_layout == L_SPLITH) { if (p->parent_layout == L_SPLITH) {
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(p->color->indicator), draw_util_rectangle(conn, &(con->frame_buffer), p->color->indicator,
r->width + (br.width + br.x), br.y, -(br.width + br.x), r->height + br.height); r->width + (br.width + br.x), br.y, -(br.width + br.x), r->height + br.height);
} else if (p->parent_layout == L_SPLITV) { } else if (p->parent_layout == L_SPLITV) {
draw_util_rectangle(conn, &(con->frame_buffer), draw_util_colorpixel_to_color(p->color->indicator), draw_util_rectangle(conn, &(con->frame_buffer), p->color->indicator,
br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y)); br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y));
} }
} }
@ -524,7 +524,7 @@ void x_draw_decoration(Con *con) {
goto copy_pixmaps; goto copy_pixmaps;
/* 4: paint the bar */ /* 4: paint the bar */
draw_util_rectangle(conn, &(parent->frame_buffer), draw_util_colorpixel_to_color(p->color->background), draw_util_rectangle(conn, &(parent->frame_buffer), p->color->background,
con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height); con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height);
/* 5: draw two unconnected horizontal lines in border color */ /* 5: draw two unconnected horizontal lines in border color */
@ -545,7 +545,7 @@ void x_draw_decoration(Con *con) {
i3String *title = i3string_from_utf8(_title); i3String *title = i3string_from_utf8(_title);
draw_util_text(title, &(parent->frame_buffer), draw_util_text(title, &(parent->frame_buffer),
draw_util_colorpixel_to_color(p->color->text), draw_util_colorpixel_to_color(p->color->background), p->color->text, p->color->background,
con->deco_rect.x + 2, con->deco_rect.y + text_offset_y, con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
con->deco_rect.width - 2); con->deco_rect.width - 2);
FREE(_title); FREE(_title);
@ -596,7 +596,7 @@ void x_draw_decoration(Con *con) {
mark_width = predict_text_width(mark); mark_width = predict_text_width(mark);
draw_util_text(mark, &(parent->frame_buffer), draw_util_text(mark, &(parent->frame_buffer),
draw_util_colorpixel_to_color(p->color->text), draw_util_colorpixel_to_color(p->color->background), p->color->text, p->color->background,
con->deco_rect.x + con->deco_rect.width - mark_width - logical_px(2), con->deco_rect.x + con->deco_rect.width - mark_width - logical_px(2),
con->deco_rect.y + text_offset_y, mark_width); con->deco_rect.y + text_offset_y, mark_width);
@ -608,7 +608,7 @@ void x_draw_decoration(Con *con) {
i3String *title = win->title_format == NULL ? win->name : window_parse_title_format(win); i3String *title = win->title_format == NULL ? win->name : window_parse_title_format(win);
draw_util_text(title, &(parent->frame_buffer), draw_util_text(title, &(parent->frame_buffer),
draw_util_colorpixel_to_color(p->color->text), draw_util_colorpixel_to_color(p->color->background), p->color->text, p->color->background,
con->deco_rect.x + logical_px(2) + indent_px, con->deco_rect.y + text_offset_y, con->deco_rect.x + logical_px(2) + indent_px, con->deco_rect.y + text_offset_y,
con->deco_rect.width - logical_px(2) - indent_px - mark_width - logical_px(2)); con->deco_rect.width - logical_px(2) - indent_px - mark_width - logical_px(2));
if (win->title_format != NULL) if (win->title_format != NULL)