diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2015-01-17 15:25:50 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2015-01-17 15:25:50 +0200 |
commit | 6ac8d8c4d8b12b37e664fd1d0c034c8fdef9c5f4 (patch) | |
tree | 090a8fb647f744d22429479ff11933cf72ef14b1 | |
parent | 96cc64a597b9cac555289f472e1867a220007e7a (diff) | |
download | bemenu-6ac8d8c4d8b12b37e664fd1d0c034c8fdef9c5f4.tar.gz bemenu-6ac8d8c4d8b12b37e664fd1d0c034c8fdef9c5f4.tar.bz2 bemenu-6ac8d8c4d8b12b37e664fd1d0c034c8fdef9c5f4.zip |
Change font functions to function on pango style font descriptions instead of size
and name.
-rw-r--r-- | client/bemenu-run.c | 2 | ||||
-rw-r--r-- | client/bemenu.c | 2 | ||||
-rw-r--r-- | client/common/common.c | 5 | ||||
-rw-r--r-- | client/common/common.h | 3 | ||||
-rw-r--r-- | lib/bemenu.h | 15 | ||||
-rw-r--r-- | lib/internal.h | 5 | ||||
-rw-r--r-- | lib/menu.c | 10 | ||||
-rw-r--r-- | lib/renderers/cairo.h | 5 |
8 files changed, 15 insertions, 32 deletions
diff --git a/client/bemenu-run.c b/client/bemenu-run.c index 9ef7b66..32f758c 100644 --- a/client/bemenu-run.c +++ b/client/bemenu-run.c @@ -18,7 +18,6 @@ static struct client client = { .prefix = NULL, .renderer = NULL, .font = NULL, - .font_size = 0, .selected = 0, .bottom = 0, .grab = 0, @@ -236,7 +235,6 @@ main(int argc, char **argv) launch(bm_menu_get_filter(menu)); } - free(client.font); bm_menu_free(menu); return (status == BM_RUN_RESULT_SELECTED ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/client/bemenu.c b/client/bemenu.c index b344443..338617c 100644 --- a/client/bemenu.c +++ b/client/bemenu.c @@ -14,7 +14,6 @@ static struct client client = { .prefix = NULL, .renderer = NULL, .font = NULL, - .font_size = 0, .selected = 0, .bottom = 0, .grab = 0, @@ -93,7 +92,6 @@ main(int argc, char **argv) printf("%s\n", bm_menu_get_filter(menu)); } - free(client.font); bm_menu_free(menu); return (status == BM_RUN_RESULT_SELECTED ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/client/common/common.c b/client/common/common.c index 078a525..e5eede5 100644 --- a/client/common/common.c +++ b/client/common/common.c @@ -191,8 +191,7 @@ parse_args(struct client *client, int *argc, char **argv[]) break; case 0x102: - if (sscanf(optarg, "%ms %u", &client->font, &client->font_size) < 2) - sscanf(optarg, "%ms", &client->font); + client->font = optarg; break; case 0x103: client->colors[BM_COLOR_BG] = optarg; @@ -251,7 +250,7 @@ menu_with_options(struct client *client) if (!(menu = bm_menu_new(client->renderer, client->prioritory))) return NULL; - bm_menu_set_font(menu, client->font, client->font_size); + bm_menu_set_font(menu, client->font); bm_menu_set_title(menu, client->title); bm_menu_set_prefix(menu, client->prefix); bm_menu_set_filter_mode(menu, client->filter_mode); diff --git a/client/common/common.h b/client/common/common.h index e710236..bae498f 100644 --- a/client/common/common.h +++ b/client/common/common.h @@ -12,8 +12,7 @@ struct client { const char *title; const char *prefix; const char *renderer; - char *font; - uint32_t font_size; + const char *font; int32_t selected; int32_t bottom; int32_t grab; diff --git a/lib/bemenu.h b/lib/bemenu.h index e968d26..63cf634 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -353,22 +353,21 @@ bool bm_menu_set_title(struct bm_menu *menu, const char *title); const char* bm_menu_get_title(const struct bm_menu *menu); /** - * Set font to bm_menu instance. + * Set font description to bm_menu instance. * - * @param font C "string" to set as font, can be **NULL** for default (Terminus). - * @param size Size for the font, may be set 0 for default. + * @param menu bm_menu instance where to set font. + * @param font C "string" for a **pango style font description**, can be **NULL** for default (Terminus 9). * @return true if set was succesful, false if out of memory. */ -bool bm_menu_set_font(struct bm_menu *menu, const char *font, uint32_t size); +bool bm_menu_set_font(struct bm_menu *menu, const char *font); /** - * Get font from bm_menu instance. + * Get font description from bm_menu instance. * - * @param menu bm_menu instance where to get font from. - * @param out_size Reference to uint32_t, will be se to size of the font. May set **NULL** for no-op. + * @param menu bm_menu instance where to get font description from. * @return Pointer to null terminated C "string". */ -const char* bm_menu_get_font(const struct bm_menu *menu, uint32_t *out_size); +const char* bm_menu_get_font(const struct bm_menu *menu); /** * Set a hexadecimal color for element. diff --git a/lib/internal.h b/lib/internal.h index 290a2f7..112e7bd 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -173,11 +173,6 @@ struct bm_font { * Name of the font. */ char *name; - - /** - * Size of font. - */ - uint32_t size; }; /** @@ -9,7 +9,7 @@ /** * Default font. */ -static const char *default_font = "Terminus"; +static const char *default_font = "Terminus 9"; /** * Default hexadecimal colors. @@ -78,7 +78,7 @@ bm_menu_new(const char *renderer, enum bm_prioritory prioritory) if (!menu->renderer) goto fail; - if (!bm_menu_set_font(menu, NULL, 0)) + if (!bm_menu_set_font(menu, NULL)) goto fail; for (uint32_t i = 0; i < BM_COLOR_LAST; ++i) { @@ -232,7 +232,7 @@ bm_menu_get_title(const struct bm_menu *menu) } bool -bm_menu_set_font(struct bm_menu *menu, const char *font, uint32_t size) +bm_menu_set_font(struct bm_menu *menu, const char *font) { assert(menu); @@ -244,15 +244,13 @@ bm_menu_set_font(struct bm_menu *menu, const char *font, uint32_t size) free(menu->font.name); menu->font.name = copy; - menu->font.size = (size > 0 ? size : 12); return true; } const char* -bm_menu_get_font(const struct bm_menu *menu, uint32_t *out_size) +bm_menu_get_font(const struct bm_menu *menu) { assert(menu); - if (out_size) *out_size = menu->font.size; return menu->font.name; } diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index 3fc1c90..5eb5b68 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -169,9 +169,6 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma memset(out_result, 0, sizeof(struct cairo_paint_result)); out_result->displayed = 1; - char font[128]; - snprintf(font, sizeof(font), "%s %d", menu->font.name, menu->font.size); - struct cairo_color c; bm_cairo_color_from_menu_color(menu, BM_COLOR_BG, &c); cairo_set_source_rgb(cairo->cr, c.r, c.g, c.b); @@ -180,7 +177,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma struct cairo_paint paint; memset(&paint, 0, sizeof(paint)); - paint.font = font; + paint.font = menu->font.name; struct cairo_result result; memset(&result, 0, sizeof(result)); |