struct wlr_texture;
struct wlr_box;
+struct font {
+ char *name;
+ int size;
+};
+
/**
* font_height - get font vertical extents
- * @font_description: string describing font, for example 'sans 10'
+ * @font: description of font including family name and size
*/
-int font_height(const char *font_description);
+int font_height(struct font *font);
/**
* texture_create - Create ARGB8888 texture using pango
* @color: foreground color in rgba format
*/
void font_texture_create(struct server *server, struct wlr_texture **texture,
- int max_width, const char *text, const char *font, float *color);
+ int max_width, const char *text, struct font *font, float *color);
/**
* font_finish - free some font related resources
#include "labwc.h"
static PangoRectangle
-font_extents(const char *font_description, const char *string)
+font_extents(struct font *font, const char *string)
{
PangoRectangle rect;
cairo_surface_t *surface;
cairo_t *c;
PangoLayout *layout;
- PangoFontDescription *font;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
c = cairo_create(surface);
layout = pango_cairo_create_layout(c);
- font = pango_font_description_from_string(font_description);
+ PangoFontDescription *desc = pango_font_description_new();
+ pango_font_description_set_family(desc, font->name);
+ pango_font_description_set_size(desc, font->size * PANGO_SCALE);
- pango_layout_set_font_description(layout, font);
+ pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, string, -1);
pango_layout_set_single_paragraph_mode(layout, TRUE);
pango_layout_set_width(layout, -1);
cairo_destroy(c);
cairo_surface_destroy(surface);
- pango_font_description_free(font);
+ pango_font_description_free(desc);
g_object_unref(layout);
return rect;
}
int
-font_height(const char *font_description)
+font_height(struct font *font)
{
- PangoRectangle rectangle;
- rectangle = font_extents(font_description, "abcdefg");
+ PangoRectangle rectangle = font_extents(font, "abcdefg");
return rectangle.height;
}
void
font_texture_create(struct server *server, struct wlr_texture **texture,
- int max_width, const char *text, const char *font, float *color)
+ int max_width, const char *text, struct font *font, float *color)
{
if (!text || !*text) {
return;
pango_layout_set_text(layout, text, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
- PangoFontDescription *desc = pango_font_description_from_string(font);
+ PangoFontDescription *desc = pango_font_description_new();
+ pango_font_description_set_family(desc, font->name);
+ pango_font_description_set_size(desc, font->size * PANGO_SCALE);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
pango_cairo_update_layout(cairo, layout);
static struct menuitem *current_item;
#define MENUWIDTH (110)
-#define MENUHEIGHT (25)
-#define MENU_PADDING_WIDTH (7)
+#define MENU_ITEM_PADDING_Y (4)
+#define MENU_ITEM_PADDING_X (7)
static struct menuitem *
menuitem_create(struct server *server, struct menu *menu, const char *text)
return NULL;
}
struct theme *theme = server->theme;
+ struct font font = {
+ .name = rc.font_name_menuitem,
+ .size = rc.font_size_menuitem,
+ };
+
menuitem->box.width = MENUWIDTH;
- menuitem->box.height = MENUHEIGHT;
+ menuitem->box.height = font_height(&font) + 2 * MENU_ITEM_PADDING_Y;
- /* TODO: use rc.font_menu_item */
- font_texture_create(server, &menuitem->texture.active, MENUWIDTH,
- text, rc.font_name_activewindow, theme->menu_items_active_text_color);
- font_texture_create(server, &menuitem->texture.inactive, MENUWIDTH,
- text, rc.font_name_activewindow, theme->menu_items_text_color);
+ int item_max_width = MENUWIDTH - 2 * MENU_ITEM_PADDING_X;
+ font_texture_create(server, &menuitem->texture.active, item_max_width,
+ text, &font, theme->menu_items_active_text_color);
+ font_texture_create(server, &menuitem->texture.inactive, item_max_width,
+ text, &font, theme->menu_items_text_color);
/* center align vertically */
menuitem->texture.offset_y =
(menuitem->box.height - menuitem->texture.active->height) / 2;
- menuitem->texture.offset_x = MENU_PADDING_WIDTH;
+ menuitem->texture.offset_x = MENU_ITEM_PADDING_X;
wl_list_insert(&menu->menuitems, &menuitem->link);
return menuitem;
y = OSD_BORDER_WIDTH;
/* vertically center align */
- y += (OSD_ITEM_HEIGHT - font_height("sans 10")) / 2;
+ struct font font = {
+ .name = "sans",
+ .size = 10,
+ };
+ y += (OSD_ITEM_HEIGHT - font_height(&font)) / 2;
wl_list_for_each(view, &server->views, link) {
if (!isfocusable(view)) {
{
struct theme *theme = view->server->theme;
- /* TODO: use window.active.label.text.color here */
- /* TODO: set max_width propertly */
- font_texture_create(view->server, &view->title, 200,
- view->impl->get_string_prop(view, "title"),
- rc.font_name_activewindow,
- theme->menu_items_active_text_color);
+ struct font font = {
+ .name = rc.font_name_activewindow,
+ .size = rc.font_size_activewindow,
+ };
+ /* get the size we can play within */
struct ssd_part *part;
wl_list_for_each(part, &view->ssd.parts, link) {
if (part->type == LAB_SSD_PART_TITLE) {
- part->box = ssd_box(view, part->type);
+ part->box = ssd_box(view, LAB_SSD_PART_TITLEBAR);
break;
}
}
+
+ /* TODO: use window.active.label.text.color here */
+ font_texture_create(view->server, &view->title, part->box.width,
+ view->impl->get_string_prop(view, "title"),
+ &font, theme->menu_items_active_text_color);
+
+ part->box = ssd_box(view, LAB_SSD_PART_TITLE);
}
void
static void
post_processing(struct theme *theme)
{
- char buf[256];
- snprintf(buf, sizeof(buf), "%s %d", rc.font_name_activewindow,
- rc.font_size_activewindow);
- theme->title_height = font_height(buf) + 2 * theme->padding_height;
+ struct font font = {
+ .name = rc.font_name_activewindow,
+ .size = rc.font_size_activewindow,
+ };
+ theme->title_height = font_height(&font) + 2 * theme->padding_height;
if (rc.corner_radius >= theme->title_height) {
theme->title_height = rc.corner_radius + 1;