all repos — tint2 @ 78bc8b5c744c6b78f7853acb68855e4116ea704c

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Draw border on only some sides (issue #580, thanks @stophe)
o9000 mrovi9000@gmail.com
commit

78bc8b5c744c6b78f7853acb68855e4116ea704c

parent

5a5d8fd9784b3ceac5b51954099c686660ad1cde

5 files changed, 85 insertions(+), 15 deletions(-)

jump to
M src/config.csrc/config.c

@@ -239,6 +239,19 @@ read_bg_color_press = 0;

read_border_color_press = 0; } else if (strcmp(key, "border_width") == 0) { g_array_index(backgrounds, Background, backgrounds->len - 1).border.width = atoi(value); + } else if (strcmp(key, "border_sides") == 0) { + Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); + bg->border.mask = 0; + if (strchr(value, 'l') || strchr(value, 'L')) + bg->border.mask |= BORDER_LEFT; + if (strchr(value, 'r') || strchr(value, 'R')) + bg->border.mask |= BORDER_RIGHT; + if (strchr(value, 't') || strchr(value, 'T')) + bg->border.mask |= BORDER_TOP; + if (strchr(value, 'b') || strchr(value, 'B')) + bg->border.mask |= BORDER_BOTTOM; + if (!bg->border.mask) + bg->border.width = 0; } else if (strcmp(key, "background_color") == 0) { Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); extract_values(value, &value1, &value2, &value3);
M src/util/area.csrc/util/area.c

@@ -36,6 +36,7 @@

void init_background(Background *bg) { memset(bg, 0, sizeof(Background)); + bg->border.mask = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT; } void initialize_positions(void *obj, int offset)

@@ -454,12 +455,18 @@ a->bg->fill_color.rgb[0],

a->bg->fill_color.rgb[1], a->bg->fill_color.rgb[2], a->bg->fill_color.alpha); + // Not sure about this draw_rect(c, - a->bg->border.width, - a->bg->border.width, - a->width - (2.0 * a->bg->border.width), - a->height - (2.0 * a->bg->border.width), + a->bg->border.mask & BORDER_LEFT ? a->bg->border.width : 0, + a->bg->border.mask & BORDER_TOP ? a->bg->border.width : 0, + a->width + - (a->bg->border.mask & BORDER_LEFT ? a->bg->border.width : 0) + - (a->bg->border.mask & BORDER_RIGHT ? a->bg->border.width : 0), + a->height + - (a->bg->border.mask & BORDER_TOP ? a->bg->border.width : 0) + - (a->bg->border.mask & BORDER_BOTTOM ? a->bg->border.width : 0), a->bg->border.radius - a->bg->border.width / 1.571); + cairo_fill(c); }

@@ -485,12 +492,17 @@ a->bg->border.color.rgb[0],

a->bg->border.color.rgb[1], a->bg->border.color.rgb[2], a->bg->border.color.alpha); - draw_rect(c, - a->bg->border.width / 2.0, - a->bg->border.width / 2.0, - a->width - a->bg->border.width, - a->height - a->bg->border.width, - a->bg->border.radius); + draw_rect_on_sides(c, + a->bg->border.mask & BORDER_LEFT ? a->bg->border.width / 2. : 0, + a->bg->border.mask & BORDER_TOP ? a->bg->border.width / 2.0 : 0, + a->width + - (a->bg->border.mask & BORDER_LEFT ? a->bg->border.width / 2. : 0) + - (a->bg->border.mask & BORDER_RIGHT ? a->bg->border.width / 2. : 0), + a->height + - (a->bg->border.mask & BORDER_TOP ? a->bg->border.width / 2. : 0) + - (a->bg->border.mask & BORDER_BOTTOM ? a->bg->border.width / 2. : 0), + a->bg->border.radius, + a->bg->border.mask); cairo_stroke(c); }
M src/util/area.hsrc/util/area.h

@@ -124,6 +124,15 @@ // Values are in [0, 1], with 0 meaning fully transparent, 1 meaning fully opaque.

double alpha; } Color; +typedef enum BorderMask { + BORDER_TOP = 1 << 0, + BORDER_BOTTOM = 1 << 1, + BORDER_LEFT = 1 << 2, + BORDER_RIGHT = 1 << 3 +} BorderMask; + +#define BORDER_ALL (BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT) + typedef struct Border { // It's essential that the first member is color Color color;

@@ -131,6 +140,8 @@ // Width in pixels

int width; // Corner radius int radius; + // Mask: bitwise OR of BorderMask + int mask; } Border; typedef struct Background {
M src/util/common.csrc/util/common.c

@@ -508,20 +508,53 @@ }

void draw_rect(cairo_t *c, double x, double y, double w, double h, double r) { - if (r > 0.0) { - double c1 = 0.55228475 * r; + draw_rect_on_sides(c, x, y, w, h, r, BORDER_ALL); +} - cairo_move_to(c, x + r, y); +void draw_rect_on_sides(cairo_t *c, double x, double y, double w, double h, double r, int border_mask) +{ + double c1 = 0.55228475 * r; + cairo_move_to(c, x + r, y); + // Top line + if (border_mask & BORDER_TOP) cairo_rel_line_to(c, w - 2 * r, 0); + else + cairo_rel_move_to(c, w - 2 * r, y); + // Top right corner + if (r > 0 && (border_mask & BORDER_TOP) && (border_mask & BORDER_RIGHT)) cairo_rel_curve_to(c, c1, 0.0, r, c1, r, r); + else + cairo_rel_move_to(c, r, r); + // Right line + if (border_mask & BORDER_RIGHT) cairo_rel_line_to(c, 0, h - 2 * r); + else + cairo_rel_move_to(c, 0, h - 2 * r); + // Bottom right corner + if (r > 0 && (border_mask & BORDER_RIGHT) && (border_mask & BORDER_BOTTOM)) cairo_rel_curve_to(c, 0.0, c1, c1 - r, r, -r, r); + else + cairo_rel_move_to(c, -r, r); + // Bottom line + if (border_mask & BORDER_BOTTOM) cairo_rel_line_to(c, -w + 2 * r, 0); + else + cairo_rel_move_to(c, -w + 2 * r, 0); + // Bottom left corner + if (r > 0 && (border_mask & BORDER_LEFT) && (border_mask & BORDER_BOTTOM)) cairo_rel_curve_to(c, -c1, 0, -r, -c1, -r, -r); + else + cairo_rel_move_to(c, -r, -r); + // Left line + if (border_mask & BORDER_LEFT) cairo_rel_line_to(c, 0, -h + 2 * r); + else + cairo_rel_move_to(c, 0, -h + 2 * r); + // Top left corner + if (r > 0 && (border_mask & BORDER_LEFT) && (border_mask & BORDER_TOP)) cairo_rel_curve_to(c, 0, -c1, r - c1, -r, r, -r); - } else - cairo_rectangle(c, x, y, w, h); + else + cairo_rel_move_to(c, r, -r); } void clear_pixmap(Pixmap p, int x, int y, int w, int h)
M src/util/common.hsrc/util/common.h

@@ -108,6 +108,7 @@ void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow);

// Draws a rounded rectangle void draw_rect(cairo_t *c, double x, double y, double w, double h, double r); +void draw_rect_on_sides(cairo_t *c, double x, double y, double w, double h, double r, int border_mask); // Clears the pixmap (with transparent color) void clear_pixmap(Pixmap p, int x, int y, int w, int h);