summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2015-01-16 01:48:47 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2015-01-16 01:48:47 +0200
commit0cd1c991d20c5c10190e520071691e849541f619 (patch)
tree5afb4a8e1e99fce2e936b05e593d4406a1cc139b
parent2bf8bbfcde0f2cb4d2ddc7a633d1f03933368c0a (diff)
downloadbemenu-0cd1c991d20c5c10190e520071691e849541f619.tar.gz
bemenu-0cd1c991d20c5c10190e520071691e849541f619.tar.bz2
bemenu-0cd1c991d20c5c10190e520071691e849541f619.zip
Take monitor height into account again.
-rw-r--r--lib/renderers/cairo.h15
-rw-r--r--lib/renderers/wayland/wayland.c2
-rw-r--r--lib/renderers/wayland/wayland.h2
-rw-r--r--lib/renderers/wayland/window.c6
4 files changed, 18 insertions, 7 deletions
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 <string.h>
#include <assert.h>
+#include <math.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
@@ -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)