]> git.sur5r.net Git - i3/i3/commitdiff
Parse colors as color_t instead of colorpixel.
authorIngo Bürk <ingo.buerk@tngtech.com>
Mon, 16 Nov 2015 22:03:39 +0000 (23:03 +0100)
committerIngo Bürk <ingo.buerk@tngtech.com>
Mon, 23 Nov 2015 21:18:02 +0000 (22:18 +0100)
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

include/config.h
include/data.h
include/libi3.h
libi3/draw_util.c
src/config.c
src/config_directives.c
src/resize.c
src/restore_layout.c
src/x.c

index 5b98ce6ebf432e9dea04ab886d3a8329e912c406..f9badf10a224d7879a989a5d987996181fe5f765 100644 (file)
@@ -50,10 +50,10 @@ struct context {
  *
  */
 struct Colortriple {
-    uint32_t border;
-    uint32_t background;
-    uint32_t text;
-    uint32_t indicator;
+    color_t border;
+    color_t background;
+    color_t text;
+    color_t indicator;
 };
 
 /**
@@ -202,7 +202,7 @@ struct Config {
 
     /* Color codes are stored here */
     struct config_client {
-        uint32_t background;
+        color_t background;
         struct Colortriple focused;
         struct Colortriple focused_inactive;
         struct Colortriple unfocused;
index 78a42ff4b9a040d78fb899bae399ada744de166d..636092d24aae4d024d12bc6d49fbfc3db482a5ae 100644 (file)
@@ -179,7 +179,7 @@ struct deco_render_params {
     struct width_height con_rect;
     struct width_height con_window_rect;
     Rect con_deco_rect;
-    uint32_t background;
+    color_t background;
     layout_t parent_layout;
     bool con_is_leaf;
 };
index 0cb2532fcd491818bda8434f5cb5d1b96137ec9b..02988837ebcdf3240f166d3ab94f561a1e73c240 100644 (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_colorpixel_to_color(uint32_t colorpixel);
-
 /**
  * Draw the given text using libi3.
  * This function also marks the surface dirty which is needed if other means of
index 816a81df2472a68b1ebfc397e6c0f1c8c2e3937b..4015ba92faf0270b2369f9c6f0cdbea0b74382ed 100644 (file)
@@ -99,14 +99,6 @@ color_t draw_util_hex_to_color(const char *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.
  *
index fac4e265cf9e70130398b4c1b1a817e46e8896e3..833ea6b638d5bb9be23e14525fb999e2b31a65c6 100644 (file)
@@ -191,13 +191,13 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
 /* Initialize default colors */
 #define INIT_COLOR(x, cborder, cbackground, ctext, cindicator) \
     do {                                                       \
-        x.border = get_colorpixel(cborder);                    \
-        x.background = get_colorpixel(cbackground);            \
-        x.text = get_colorpixel(ctext);                        \
-        x.indicator = get_colorpixel(cindicator);              \
+        x.border = draw_util_hex_to_color(cborder);            \
+        x.background = draw_util_hex_to_color(cbackground);    \
+        x.text = draw_util_hex_to_color(ctext);                \
+        x.indicator = draw_util_hex_to_color(cindicator);      \
     } 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_inactive, "#333333", "#5f676a", "#ffffff", "#484e50");
     INIT_COLOR(config.client.unfocused, "#333333", "#222222", "#888888", "#292d2e");
index ba26742780fe4324bf8a04cd88f69646006f379b..0d32f0085c0cc279799b2295f5c794d827d8fad8 100644 (file)
@@ -332,20 +332,20 @@ CFGFUN(popup_during_fullscreen, const char *value) {
 
 CFGFUN(color_single, const char *colorclass, const char *color) {
     /* 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) {
-#define APPLY_COLORS(classname)                                                \
-    do {                                                                       \
-        if (strcmp(colorclass, "client." #classname) == 0) {                   \
-            config.client.classname.border = get_colorpixel(border);           \
-            config.client.classname.background = get_colorpixel(background);   \
-            config.client.classname.text = get_colorpixel(text);               \
-            if (indicator != NULL) {                                           \
-                config.client.classname.indicator = get_colorpixel(indicator); \
-            }                                                                  \
-        }                                                                      \
+#define APPLY_COLORS(classname)                                                        \
+    do {                                                                               \
+        if (strcmp(colorclass, "client." #classname) == 0) {                           \
+            config.client.classname.border = draw_util_hex_to_color(border);           \
+            config.client.classname.background = draw_util_hex_to_color(background);   \
+            config.client.classname.text = draw_util_hex_to_color(text);               \
+            if (indicator != NULL) {                                                   \
+                config.client.classname.indicator = draw_util_hex_to_color(indicator); \
+            }                                                                          \
+        }                                                                              \
     } while (0)
 
     APPLY_COLORS(focused_inactive);
index 05fe50558dba737352efc15333b362cf4ce69e20..31a783542704d7dad6176f37c2ba8a3006adb240 100644 (file)
@@ -146,7 +146,7 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
     }
 
     mask = XCB_CW_BACK_PIXEL;
-    values[0] = config.client.focused.border;
+    values[0] = config.client.focused.border.colorpixel;
 
     mask |= XCB_CW_OVERRIDE_REDIRECT;
     values[1] = 1;
index 70eed523a6d5337689ccc79bc9f030d206af67ed..5ca4cff57dffe3cb70c4c3c6107b110112410d98 100644 (file)
@@ -125,7 +125,7 @@ void restore_connect(void) {
 
 static void update_placeholder_contents(placeholder_state *state) {
     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_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_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;
     int n = 0;
@@ -193,7 +193,7 @@ static void open_placeholder_window(Con *con) {
             true,
             XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
             (uint32_t[]){
-                config.client.placeholder.background,
+                config.client.placeholder.background.colorpixel,
                 XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY,
             });
         /* Make i3 not focus this window. */
diff --git a/src/x.c b/src/x.c
index 49325af4fe02a3e0af4dafa352ed24d2193ec559..63cc4b48b36a8ab353ed454803eff2ec0dc68efc 100644 (file)
--- a/src/x.c
+++ b/src/x.c
@@ -327,10 +327,10 @@ static void x_draw_decoration_border(Con *con, struct deco_render_params *p) {
         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);
 
-    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);
 }
 
@@ -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.
      * 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. */
-    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);
 
     /* Draw a 1px separator line before and after every tab, so that tabs can
      * be easily distinguished. */
     if (con->parent->layout == L_TABBED) {
         /* 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);
 
         /* 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);
     }
 
@@ -448,16 +448,16 @@ void x_draw_decoration(Con *con) {
     /* 2: draw the client.background, but only for the parts around the window_rect */
     if (con->window != NULL) {
         /* 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);
         /* 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));
         /* 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);
         /* 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);
     }
 
@@ -479,20 +479,20 @@ void x_draw_decoration(Con *con) {
          * rectangle because some childs are not freely resizable and we want
          * their background color to "shine through". */
         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);
         }
         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);
         }
         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));
         }
         /* pixel border needs an additional line at the top */
         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);
         }
 
@@ -504,10 +504,10 @@ void x_draw_decoration(Con *con) {
             TAILQ_PREV(con, nodes_head, nodes) == NULL &&
             con->parent->type != CT_FLOATING_CON) {
             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);
             } 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));
             }
         }
@@ -524,7 +524,7 @@ void x_draw_decoration(Con *con) {
         goto copy_pixmaps;
 
     /* 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);
 
     /* 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);
         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.width - 2);
         FREE(_title);
@@ -596,7 +596,7 @@ void x_draw_decoration(Con *con) {
             mark_width = predict_text_width(mark);
 
             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.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);
     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.width - logical_px(2) - indent_px - mark_width - logical_px(2));
     if (win->title_format != NULL)