Rename draw functions
Remove prefixes used to distinguish between X and draw functions in x.c, this is obviously no longer necessary. Additionally, add appropriate layout_ and color_ prefixes to the relevant functions.
This commit is contained in:
parent
f02626e1a7
commit
e52b1ae495
66
src/draw.c
66
src/draw.c
@ -45,7 +45,7 @@ void draw_setup(void)
|
|||||||
pango_fdesc = pango_font_description_from_string(settings.font);
|
pango_fdesc = pango_font_description_from_string(settings.font);
|
||||||
}
|
}
|
||||||
|
|
||||||
static color_t x_color_hex_to_double(int hexValue)
|
static color_t color_hex_to_double(int hexValue)
|
||||||
{
|
{
|
||||||
color_t color;
|
color_t color;
|
||||||
color.r = ((hexValue >> 16) & 0xFF) / 255.0;
|
color.r = ((hexValue >> 16) & 0xFF) / 255.0;
|
||||||
@ -55,7 +55,7 @@ static color_t x_color_hex_to_double(int hexValue)
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
static color_t x_string_to_color_t(const char *str)
|
static color_t string_to_color(const char *str)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
long int val = strtol(str+1, &end, 16);
|
long int val = strtol(str+1, &end, 16);
|
||||||
@ -63,10 +63,10 @@ static color_t x_string_to_color_t(const char *str)
|
|||||||
LOG_W("Invalid color string: '%s'", str);
|
LOG_W("Invalid color string: '%s'", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
return x_color_hex_to_double(val);
|
return color_hex_to_double(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double _apply_delta(double base, double delta)
|
static double color_apply_delta(double base, double delta)
|
||||||
{
|
{
|
||||||
base += delta;
|
base += delta;
|
||||||
if (base > 1)
|
if (base > 1)
|
||||||
@ -87,14 +87,14 @@ static color_t calculate_foreground_color(color_t bg)
|
|||||||
|
|
||||||
int signedness = darken ? -1 : 1;
|
int signedness = darken ? -1 : 1;
|
||||||
|
|
||||||
color.r = _apply_delta(color.r, c_delta * signedness);
|
color.r = color_apply_delta(color.r, c_delta * signedness);
|
||||||
color.g = _apply_delta(color.g, c_delta * signedness);
|
color.g = color_apply_delta(color.g, c_delta * signedness);
|
||||||
color.b = _apply_delta(color.b, c_delta * signedness);
|
color.b = color_apply_delta(color.b, c_delta * signedness);
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
static color_t x_get_separator_color(colored_layout *cl, colored_layout *cl_next)
|
static color_t layout_get_sepcolor(colored_layout *cl, colored_layout *cl_next)
|
||||||
{
|
{
|
||||||
switch (settings.sep_color) {
|
switch (settings.sep_color) {
|
||||||
case FRAME:
|
case FRAME:
|
||||||
@ -103,7 +103,7 @@ static color_t x_get_separator_color(colored_layout *cl, colored_layout *cl_next
|
|||||||
else
|
else
|
||||||
return cl->frame;
|
return cl->frame;
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
return x_string_to_color_t(settings.sep_custom_color_str);
|
return string_to_color(settings.sep_custom_color_str);
|
||||||
case FOREGROUND:
|
case FOREGROUND:
|
||||||
return cl->fg;
|
return cl->fg;
|
||||||
case AUTO:
|
case AUTO:
|
||||||
@ -113,7 +113,7 @@ static color_t x_get_separator_color(colored_layout *cl, colored_layout *cl_next
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void r_setup_pango_layout(PangoLayout *layout, int width)
|
static void layout_setup_pango(PangoLayout *layout, int width)
|
||||||
{
|
{
|
||||||
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
|
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
|
||||||
pango_layout_set_width(layout, width * PANGO_SCALE);
|
pango_layout_set_width(layout, width * PANGO_SCALE);
|
||||||
@ -208,7 +208,7 @@ static struct dimensions calculate_dimensions(GSList *layouts)
|
|||||||
w -= 2 * settings.h_padding;
|
w -= 2 * settings.h_padding;
|
||||||
w -= 2 * settings.frame_width;
|
w -= 2 * settings.frame_width;
|
||||||
if (cl->icon) w -= cairo_image_surface_get_width(cl->icon) + settings.h_padding;
|
if (cl->icon) w -= cairo_image_surface_get_width(cl->icon) + settings.h_padding;
|
||||||
r_setup_pango_layout(cl->l, w);
|
layout_setup_pango(cl->l, w);
|
||||||
|
|
||||||
/* re-read information */
|
/* re-read information */
|
||||||
pango_layout_get_pixel_size(cl->l, &w, &h);
|
pango_layout_get_pixel_size(cl->l, &w, &h);
|
||||||
@ -230,7 +230,7 @@ static struct dimensions calculate_dimensions(GSList *layouts)
|
|||||||
return dim;
|
return dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PangoLayout *create_layout(cairo_t *c)
|
static PangoLayout *layout_create(cairo_t *c)
|
||||||
{
|
{
|
||||||
screen_info *screen = get_active_screen();
|
screen_info *screen = get_active_screen();
|
||||||
|
|
||||||
@ -244,10 +244,10 @@ static PangoLayout *create_layout(cairo_t *c)
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static colored_layout *r_init_shared(cairo_t *c, notification *n)
|
static colored_layout *layout_init_shared(cairo_t *c, notification *n)
|
||||||
{
|
{
|
||||||
colored_layout *cl = g_malloc(sizeof(colored_layout));
|
colored_layout *cl = g_malloc(sizeof(colored_layout));
|
||||||
cl->l = create_layout(c);
|
cl->l = layout_create(c);
|
||||||
|
|
||||||
if (!settings.word_wrap) {
|
if (!settings.word_wrap) {
|
||||||
PangoEllipsizeMode ellipsize;
|
PangoEllipsizeMode ellipsize;
|
||||||
@ -308,9 +308,9 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n)
|
|||||||
cl->icon = NULL;
|
cl->icon = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl->fg = x_string_to_color_t(n->colors[ColFG]);
|
cl->fg = string_to_color(n->colors[ColFG]);
|
||||||
cl->bg = x_string_to_color_t(n->colors[ColBG]);
|
cl->bg = string_to_color(n->colors[ColBG]);
|
||||||
cl->frame = x_string_to_color_t(n->colors[ColFrame]);
|
cl->frame = string_to_color(n->colors[ColFrame]);
|
||||||
|
|
||||||
cl->n = n;
|
cl->n = n;
|
||||||
|
|
||||||
@ -318,30 +318,30 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n)
|
|||||||
int width = dim.w;
|
int width = dim.w;
|
||||||
|
|
||||||
if (have_dynamic_width()) {
|
if (have_dynamic_width()) {
|
||||||
r_setup_pango_layout(cl->l, -1);
|
layout_setup_pango(cl->l, -1);
|
||||||
} else {
|
} else {
|
||||||
width -= 2 * settings.h_padding;
|
width -= 2 * settings.h_padding;
|
||||||
width -= 2 * settings.frame_width;
|
width -= 2 * settings.frame_width;
|
||||||
if (cl->icon) width -= cairo_image_surface_get_width(cl->icon) + settings.h_padding;
|
if (cl->icon) width -= cairo_image_surface_get_width(cl->icon) + settings.h_padding;
|
||||||
r_setup_pango_layout(cl->l, width);
|
layout_setup_pango(cl->l, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static colored_layout *r_create_layout_for_xmore(cairo_t *c, notification *n, int qlen)
|
static colored_layout *layout_derive_xmore(cairo_t *c, notification *n, int qlen)
|
||||||
{
|
{
|
||||||
colored_layout *cl = r_init_shared(c, n);
|
colored_layout *cl = layout_init_shared(c, n);
|
||||||
cl->text = g_strdup_printf("(%d more)", qlen);
|
cl->text = g_strdup_printf("(%d more)", qlen);
|
||||||
cl->attr = NULL;
|
cl->attr = NULL;
|
||||||
pango_layout_set_text(cl->l, cl->text, -1);
|
pango_layout_set_text(cl->l, cl->text, -1);
|
||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static colored_layout *r_create_layout_from_notification(cairo_t *c, notification *n)
|
static colored_layout *layout_from_notification(cairo_t *c, notification *n)
|
||||||
{
|
{
|
||||||
|
|
||||||
colored_layout *cl = r_init_shared(c, n);
|
colored_layout *cl = layout_init_shared(c, n);
|
||||||
|
|
||||||
/* markup */
|
/* markup */
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
@ -371,7 +371,7 @@ static colored_layout *r_create_layout_from_notification(cairo_t *c, notificatio
|
|||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GSList *r_create_layouts(cairo_t *c)
|
static GSList *create_layouts(cairo_t *c)
|
||||||
{
|
{
|
||||||
GSList *layouts = NULL;
|
GSList *layouts = NULL;
|
||||||
|
|
||||||
@ -393,24 +393,24 @@ static GSList *r_create_layouts(cairo_t *c)
|
|||||||
n->text_to_render = new_ttr;
|
n->text_to_render = new_ttr;
|
||||||
}
|
}
|
||||||
layouts = g_slist_append(layouts,
|
layouts = g_slist_append(layouts,
|
||||||
r_create_layout_from_notification(c, n));
|
layout_from_notification(c, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xmore_is_needed && settings.geometry.h != 1) {
|
if (xmore_is_needed && settings.geometry.h != 1) {
|
||||||
/* append xmore message as new message */
|
/* append xmore message as new message */
|
||||||
layouts = g_slist_append(layouts,
|
layouts = g_slist_append(layouts,
|
||||||
r_create_layout_for_xmore(c, last, qlen));
|
layout_derive_xmore(c, last, qlen));
|
||||||
}
|
}
|
||||||
|
|
||||||
return layouts;
|
return layouts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void r_free_layouts(GSList *layouts)
|
static void free_layouts(GSList *layouts)
|
||||||
{
|
{
|
||||||
g_slist_free_full(layouts, free_colored_layout);
|
g_slist_free_full(layouts, free_colored_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dimensions x_render_layout(cairo_t *c, colored_layout *cl, colored_layout *cl_next, struct dimensions dim, bool first, bool last)
|
static struct dimensions layout_render(cairo_t *c, colored_layout *cl, colored_layout *cl_next, struct dimensions dim, bool first, bool last)
|
||||||
{
|
{
|
||||||
int h;
|
int h;
|
||||||
int h_text = 0;
|
int h_text = 0;
|
||||||
@ -474,7 +474,7 @@ static struct dimensions x_render_layout(cairo_t *c, colored_layout *cl, colored
|
|||||||
dim.y += (int)(floor(bg_half_height) + pango_offset);
|
dim.y += (int)(floor(bg_half_height) + pango_offset);
|
||||||
|
|
||||||
if (settings.separator_height > 0 && !last) {
|
if (settings.separator_height > 0 && !last) {
|
||||||
color_t sep_color = x_get_separator_color(cl, cl_next);
|
color_t sep_color = layout_get_sepcolor(cl, cl_next);
|
||||||
cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b);
|
cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b);
|
||||||
|
|
||||||
if (settings.sep_color == FRAME)
|
if (settings.sep_color == FRAME)
|
||||||
@ -512,7 +512,7 @@ static struct dimensions x_render_layout(cairo_t *c, colored_layout *cl, colored
|
|||||||
void draw(void)
|
void draw(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
GSList *layouts = r_create_layouts(c_context);
|
GSList *layouts = create_layouts(c_context);
|
||||||
|
|
||||||
struct dimensions dim = calculate_dimensions(layouts);
|
struct dimensions dim = calculate_dimensions(layouts);
|
||||||
int width = dim.w;
|
int width = dim.w;
|
||||||
@ -530,9 +530,9 @@ void draw(void)
|
|||||||
bool first = true;
|
bool first = true;
|
||||||
for (GSList *iter = layouts; iter; iter = iter->next) {
|
for (GSList *iter = layouts; iter; iter = iter->next) {
|
||||||
if (iter->next)
|
if (iter->next)
|
||||||
dim = x_render_layout(c, iter->data, iter->next->data, dim, first, iter->next == NULL);
|
dim = layout_render(c, iter->data, iter->next->data, dim, first, iter->next == NULL);
|
||||||
else
|
else
|
||||||
dim = x_render_layout(c, iter->data, NULL, dim, first, iter->next == NULL);
|
dim = layout_render(c, iter->data, NULL, dim, first, iter->next == NULL);
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
@ -545,7 +545,7 @@ void draw(void)
|
|||||||
|
|
||||||
cairo_destroy(c);
|
cairo_destroy(c);
|
||||||
cairo_surface_destroy(image_surface);
|
cairo_surface_destroy(image_surface);
|
||||||
r_free_layouts(layouts);
|
free_layouts(layouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_deinit(void)
|
void draw_deinit(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user