~proycon/wvkbd

d423720553be863c07b077c84e7d0ac1fd77db58 — Amir Dahan a month ago e3081fb
Add basic rounding

There's probably a better way of doing this, But this will do for now.

Added basic rounding to buttons.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
5 files changed, 51 insertions(+), 27 deletions(-)

M config.def.h
M drw.c
M drw.h
M keyboard.c
M keyboard.h
M config.def.h => config.def.h +2 -0
@@ 13,6 13,7 @@ struct clr_scheme schemes[] = {
  .swipe = {.bgra = {100, 255, 100, 64}},
  .text = {.color = UINT32_MAX},
  .font = DEFAULT_FONT,
  .rounding = 5,
},
{
  /* colors */


@@ 22,6 23,7 @@ struct clr_scheme schemes[] = {
  .swipe = {.bgra = {100, 255, 100, 64}},
  .text = {.color = UINT32_MAX},
  .font = DEFAULT_FONT,
  .rounding = 5,
}
};


M drw.c => drw.c +33 -12
@@ 71,7 71,7 @@ drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w, uint32_t h)

void
drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                 uint32_t w, uint32_t h, bool over)
                 uint32_t w, uint32_t h, bool over, int rounding)
{
    cairo_save(d->cairo);



@@ 81,27 81,48 @@ drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
        cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
    }

    cairo_rectangle(d->cairo, x, y, w, h);
    cairo_set_source_rgba(
        d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
        color.bgra[0] / (double)255, color.bgra[3] / (double)255);
    cairo_fill(d->cairo);

    cairo_restore(d->cairo);
    if (rounding > 0) {
        double radius = rounding / 1.0;
        double degrees = M_PI / 180.0;

        cairo_new_sub_path (d->cairo);
        cairo_arc (d->cairo, x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
        cairo_arc (d->cairo, x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
        cairo_arc (d->cairo, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
        cairo_arc (d->cairo, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
        cairo_close_path (d->cairo);

        cairo_set_source_rgba(
          d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255, 
          color.bgra[0] / (double)255, color.bgra[3] / (double)255);
        cairo_fill (d->cairo);
        cairo_set_source_rgba(d->cairo, 0, 0, 0, 0.9);
        cairo_set_line_width(d->cairo, 1.0);
        cairo_stroke(d->cairo);
    }
    else {
        cairo_rectangle(d->cairo, x, y, w, h);
        cairo_set_source_rgba(
            d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
            color.bgra[0] / (double)255, color.bgra[3] / (double)255);
        cairo_fill(d->cairo);

        cairo_restore(d->cairo);
    }
}

void
drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                   uint32_t w, uint32_t h)
                   uint32_t w, uint32_t h, int rounding)
{
    drw_do_rectangle(d, color, x, y, w, h, false);
    drw_do_rectangle(d, color, x, y, w, h, false, rounding);
}

void
drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                   uint32_t w, uint32_t h)
                   uint32_t w, uint32_t h, int rounding)
{
    drw_do_rectangle(d, color, x, y, w, h, true);
    drw_do_rectangle(d, color, x, y, w, h, true, rounding);
}

uint32_t

M drw.h => drw.h +3 -3
@@ 33,11 33,11 @@ typedef union {
void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y,
                      uint32_t w, uint32_t h);
void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                      uint32_t w, uint32_t h, bool fill);
                      uint32_t w, uint32_t h, bool fill, int rounding);
void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                        uint32_t w, uint32_t h);
                        uint32_t w, uint32_t h, int rounding);
void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                        uint32_t w, uint32_t h);
                        uint32_t w, uint32_t h, int rounding);

void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                   uint32_t w, uint32_t h, uint32_t b, const char *label,

M keyboard.c => keyboard.c +10 -10
@@ 561,15 561,15 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
    case None:
    case Unpress:
        draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
                   scheme->fg);
                   scheme->fg, scheme->rounding);
        break;
    case Press:
        draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
                   scheme->high);
                   scheme->high, scheme->rounding);
        break;
    case Swipe:
        draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
                        scheme->swipe);
                        scheme->swipe, scheme->rounding);
        break;
    }



@@ 586,9 586,9 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
        kb->last_popup_h = k->h;

        drw_fill_rectangle(kb->popup_surf, scheme->bg, k->x,
                           kb->last_popup_y, k->w, k->h);
                           kb->last_popup_y, k->w, k->h, scheme->rounding);
        draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
                   KBD_KEY_BORDER, scheme->high);
                   KBD_KEY_BORDER, scheme->high, scheme->rounding);
        drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
                      k->w, k->h, KBD_KEY_BORDER, label,
                      scheme->font_description);


@@ 605,7 605,7 @@ kbd_draw_layout(struct kbd *kb)
    if (kb->debug)
        fprintf(stderr, "Draw layout\n");

    drw_fill_rectangle(d, kb->schemes[0].bg, 0, 0, kb->w, kb->h);
    drw_fill_rectangle(d, kb->schemes[0].bg, 0, 0, kb->w, kb->h, 0);

    while (next_key->type != Last) {
        if ((next_key->type == Pad) || (next_key->type == EndRow)) {


@@ 647,17 647,17 @@ kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount)

void
draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
           uint32_t height, uint32_t border, Color color)
           uint32_t height, uint32_t border, Color color, int rounding)
{
    drw_fill_rectangle(ds, color, x + border, y + border, width - (border * 2),
                       height - (border * 2));
                       height - (border * 2), rounding);
}
void
draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
                uint32_t height, uint32_t border, Color color)
                uint32_t height, uint32_t border, Color color, int rounding)
{
    drw_over_rectangle(ds, color, x + border, y + border, width - (border * 2),
                       height - (border * 2));
                       height - (border * 2), rounding);
}

void

M keyboard.h => keyboard.h +3 -2
@@ 55,6 55,7 @@ struct clr_scheme {
	Color swipe;
	Color text;
	char *font;
	int rounding;
	PangoFontDescription *font_description;
};



@@ 121,9 122,9 @@ struct kbd {
};

void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
                uint32_t height, uint32_t border, Color color);
                uint32_t height, uint32_t border, Color color, int rounding);
void draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
                     uint32_t height, uint32_t border, Color color);
                     uint32_t height, uint32_t border, Color color, int rounding);

void kbd_init(struct kbd *kb, struct layout *layouts,
              char *layer_names_list, char *landscape_layer_names_list);