mirror of
https://github.com/Cloudef/bemenu
synced 2024-06-01 12:26:25 +02:00
Take monitor height into account again.
This commit is contained in:
parent
2bf8bbfcde
commit
0cd1c991d2
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue