diff --git a/config.def.h b/config.def.h index 890cb77..f8db8d5 100644 --- a/config.def.h +++ b/config.def.h @@ -1,7 +1,7 @@ #ifndef config_def_h_INCLUDED #define config_def_h_INCLUDED -static const char *default_font = "Sans 14"; +#define DEFAULT_FONT "Sans 14" static const int transparency = 255; struct clr_scheme schemes[] = { @@ -12,6 +12,7 @@ struct clr_scheme schemes[] = { .high = {.bgra = {100, 100, 100, transparency}}, .swipe = {.bgra = {100, 255, 100, 64}}, .text = {.color = UINT32_MAX}, + .font = DEFAULT_FONT, }, { /* colors */ @@ -20,6 +21,7 @@ struct clr_scheme schemes[] = { .high = {.bgra = {100, 100, 100, transparency}}, .swipe = {.bgra = {100, 255, 100, 64}}, .text = {.color = UINT32_MAX}, + .font = DEFAULT_FONT, } }; diff --git a/drw.c b/drw.c index 83b4db3..5c0b242 100644 --- a/drw.c +++ b/drw.c @@ -30,11 +30,14 @@ drwsurf_flip(struct drwsurf *ds) 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) + uint32_t w, uint32_t h, uint32_t b, const char *label, + PangoFontDescription *font_description) { cairo_save(d->cairo); + pango_layout_set_font_description(d->layout, font_description); + 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); @@ -134,8 +137,6 @@ setup_buffer(struct drwsurf *drwsurf) cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale); cairo_set_antialias(drwsurf->cairo, CAIRO_ANTIALIAS_NONE); drwsurf->layout = pango_cairo_create_layout(drwsurf->cairo); - pango_layout_set_font_description(drwsurf->layout, - drwsurf->ctx->font_description); pango_layout_set_auto_dir(drwsurf->layout, false); cairo_save(drwsurf->cairo); diff --git a/drw.h b/drw.h index 2e5c919..6ebdd1c 100644 --- a/drw.h +++ b/drw.h @@ -6,7 +6,6 @@ struct drw { struct wl_shm *shm; - PangoFontDescription *font_description; }; struct drwsurf { uint32_t width, height, size; @@ -41,7 +40,8 @@ void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y, uint32_t w, uint32_t h); 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); + uint32_t w, uint32_t h, uint32_t b, const char *label, + PangoFontDescription *font_description); uint32_t setup_buffer(struct drwsurf *drwsurf); diff --git a/keyboard.c b/keyboard.c index c5faa12..afe0639 100644 --- a/keyboard.c +++ b/keyboard.c @@ -574,7 +574,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) } drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h, - KBD_KEY_BORDER, label); + KBD_KEY_BORDER, label, scheme->font_description); wl_surface_damage(kb->surf->surf, k->x, k->y, k->w, k->h); if (type == Press || type == Unpress) { @@ -590,7 +590,8 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h, KBD_KEY_BORDER, scheme->high); drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y, - k->w, k->h, KBD_KEY_BORDER, label); + k->w, k->h, KBD_KEY_BORDER, label, + scheme->font_description); wl_surface_damage(kb->popup_surf->surf, k->x, kb->last_popup_y, k->w, k->h); } diff --git a/keyboard.h b/keyboard.h index c69d228..f09b363 100644 --- a/keyboard.h +++ b/keyboard.h @@ -54,6 +54,8 @@ struct clr_scheme { Color high; Color swipe; Color text; + char *font; + PangoFontDescription *font_description; }; struct key { diff --git a/main.c b/main.c index d1f4b44..46c74b9 100644 --- a/main.c +++ b/main.c @@ -24,6 +24,9 @@ fprintf(stderr, __VA_ARGS__); \ exit(1) +/* array size */ +#define countof(x) (sizeof(x) / sizeof(*x)) + /* client state */ static const char *namespace = "wlroots"; static struct wl_display *display; @@ -747,7 +750,7 @@ main(int argc, char **argv) { /* parse command line arguments */ char *layer_names_list = NULL, *landscape_layer_names_list = NULL; - const char *fc_font_pattern = NULL; + char *fc_font_pattern = NULL; height = normal_height = KBD_PIXEL_HEIGHT; landscape_height = KBD_PIXEL_LANDSCAPE_HEIGHT; @@ -913,8 +916,9 @@ main(int argc, char **argv) keyboard.schemes[1].high.bgra[3] = alpha; } - if (!fc_font_pattern) { - fc_font_pattern = default_font; + if (fc_font_pattern) { + for (i = 0; i < countof(schemes); i++) + schemes[i].font = fc_font_pattern; } display = wl_display_connect(NULL); @@ -959,8 +963,10 @@ main(int argc, char **argv) kbd_init(&keyboard, (struct layout *)&layouts, layer_names_list, landscape_layer_names_list); - draw_ctx.font_description = - pango_font_description_from_string(fc_font_pattern); + for (i = 0; i < countof(schemes); i++) { + schemes[i].font_description = + pango_font_description_from_string(schemes[i].font); + } if (!hidden) show(); @@ -1014,8 +1020,10 @@ main(int argc, char **argv) } } - if (fc_font_pattern != default_font) { + if (fc_font_pattern) { free((void *)fc_font_pattern); + for (i = 0; i < countof(schemes); i++) + schemes[i].font = NULL; } return 0;