From 2bf8bbfcde0f2cb4d2ddc7a633d1f03933368c0a Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Thu, 15 Jan 2015 22:18:23 +0200 Subject: Working pango code. --- lib/renderers/wayland/wayland.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib/renderers/wayland/wayland.c') diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index 3852a6d..18f335f 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -39,10 +39,7 @@ render(const struct bm_menu *menu) } if (wayland->input.code != wayland->input.last_code) { - uint32_t count; - bm_menu_get_filtered_items(menu, &count); - uint32_t lines = (count < menu->lines ? count : menu->lines) + 1; - bm_wl_window_render(&wayland->window, menu, lines); + bm_wl_window_render(&wayland->window, menu); wayland->input.last_code = wayland->input.code; } } -- cgit v1.2.3-70-g09d2 From 0cd1c991d20c5c10190e520071691e849541f619 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 16 Jan 2015 01:48:47 +0200 Subject: Take monitor height into account again. --- lib/renderers/cairo.h | 15 ++++++++++++--- lib/renderers/wayland/wayland.c | 2 +- lib/renderers/wayland/wayland.h | 2 +- lib/renderers/wayland/window.c | 6 ++++-- 4 files changed, 18 insertions(+), 7 deletions(-) (limited to 'lib/renderers/wayland/wayland.c') diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index 09aebf7..3fc1c90 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -4,6 +4,7 @@ #include "internal.h" #include #include +#include #include #include @@ -161,7 +162,7 @@ bm_cairo_color_from_menu_color(const struct bm_menu *menu, enum bm_color color, } __attribute__((unused)) static void -bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struct bm_menu *menu, struct cairo_paint_result *out_result) +bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *out_result) { assert(cairo && menu && out_result); @@ -207,6 +208,14 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc if (lines > 1) { /* vertical mode */ + + uint32_t spacing = 0; // 0 == variable width spacing + if (lines > max_height / result.height) { + /* there is more lines than screen can fit, enter fixed spacing mode */ + lines = max_height / result.height - 1; + spacing = result.height; + } + uint32_t start_x = 0; if (menu->prefix) { bm_pango_get_text_extents(cairo, &paint, &result, "%s ", menu->prefix); @@ -214,7 +223,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc } uint32_t posy = out_result->height; - for (uint32_t l = 0, i = (menu->index / lines) * lines; l < lines && i < count; ++i, ++l) { + for (uint32_t l = 0, i = (menu->index / lines) * lines; l < lines && i < count && posy < max_height; ++i, ++l) { bool highlighted = (items[i] == bm_menu_get_highlighted_item(menu)); if (highlighted) { @@ -238,7 +247,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : "")); } - posy += result.height; + posy += (spacing ? spacing : result.height); out_result->height = posy + 2; out_result->displayed++; } diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index 18f335f..5d85479 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -184,7 +184,7 @@ constructor(struct bm_menu *menu) goto fail; wayland->window.width = 800; - wayland->window.height = 14; + wayland->window.height = 1; if (!(wayland->display = wl_display_connect(NULL))) goto fail; diff --git a/lib/renderers/wayland/wayland.h b/lib/renderers/wayland/wayland.h index d6c0915..dff6aba 100644 --- a/lib/renderers/wayland/wayland.h +++ b/lib/renderers/wayland/wayland.h @@ -85,7 +85,7 @@ struct window { uint32_t displayed; struct { - void (*render)(struct cairo *cairo, uint32_t width, uint32_t height, const struct bm_menu *menu, struct cairo_paint_result *result); + void (*render)(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *result); } notify; }; diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index a9c9edc..bfff232 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -149,8 +149,10 @@ create_buffer(struct wl_shm *shm, struct buffer *buffer, int32_t width, int32_t if (!(surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride))) goto fail; - if (!bm_cairo_create_for_surface(&buffer->cairo, surf)) + if (!bm_cairo_create_for_surface(&buffer->cairo, surf)) { + cairo_surface_destroy(surf); goto fail; + } buffer->width = width; buffer->height = height; @@ -266,7 +268,7 @@ bm_wl_window_render(struct window *window, const struct bm_menu *menu) break; struct cairo_paint_result result; - window->notify.render(&buffer->cairo, buffer->width, buffer->height, menu, &result); + window->notify.render(&buffer->cairo, buffer->width, fmin(buffer->height, window->max_height), window->max_height, menu, &result); window->displayed = result.displayed; if (window->height == result.height) -- cgit v1.2.3-70-g09d2