diff --git a/lib/renderers/cairo_renderer.h b/lib/renderers/cairo_renderer.h index fa867d7e..80e9cfe4 100644 --- a/lib/renderers/cairo_renderer.h +++ b/lib/renderers/cairo_renderer.h @@ -314,10 +314,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, struct uint32_t page_length = 0; if (menu->lines_mode == BM_LINES_UP && !menu->fixed_height) { - struct cairo_result dummy_result; - bm_cairo_draw_line_str(cairo, &paint, &dummy_result, ""); - - int32_t new_y_offset = (count < lines ? (lines - count) * result.height : 0); + int32_t new_y_offset = (count < lines ? (lines - count) * height : 0); bm_menu_set_y_offset(menu, new_y_offset); } @@ -330,7 +327,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, struct enum bm_color title_bg = (menu->lines_mode == BM_LINES_UP ? BM_COLOR_ITEM_BG : BM_COLOR_TITLE_BG); bm_cairo_color_from_menu_color(menu, title_fg, &paint.fg); bm_cairo_color_from_menu_color(menu, title_bg, &paint.bg); - paint.pos = (struct pos){ result.x_advance + border_size + 4, vpadding + border_size }; + paint.pos = (struct pos){ border_size + 4, vpadding + border_size }; paint.box = (struct box){ 4, 16, vpadding, -vpadding, 0, height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title); title_x = result.x_advance; @@ -528,14 +525,12 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, struct } - struct cairo_paint pre_up_drawing = paint; // Some behavior may depend on the previous paint. - if (menu->lines_mode == BM_LINES_UP) { if (menu->title) { bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_FG, &paint.fg); bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_BG, &paint.bg); - paint.pos = (struct pos){ border_size, posy + border_size }; + paint.pos = (struct pos){ border_size + 4, posy + vpadding + border_size }; paint.box = (struct box){ 4, 16, vpadding, -vpadding, 0, height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title); } @@ -570,8 +565,6 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, struct posy += (spacing_y ? spacing_y : result.height); out_result->height = posy; out_result->displayed++; - - paint = pre_up_drawing; } if (menu->counter) { diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index 8cb0f77d..74600500 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -397,6 +397,18 @@ set_align(const struct bm_menu *menu, enum bm_align align) } } +static void +set_y_offset(const struct bm_menu *menu, int32_t y_offset) +{ + struct wayland *wayland = menu->renderer->internal; + assert(wayland); + + struct window *window; + wl_list_for_each(window, &wayland->windows, link) { + bm_wl_window_set_y_offset(window, wayland->display, y_offset); + } +} + static void grab_keyboard(const struct bm_menu *menu, bool grab) { @@ -672,6 +684,7 @@ register_renderer(struct render_api *api) api->release_touch = release_touch; api->render = render; api->set_align = set_align; + api->set_y_offset = set_y_offset; api->set_width = set_width; api->grab_keyboard = grab_keyboard; api->set_overlap = set_overlap; diff --git a/lib/renderers/wayland/wayland.h b/lib/renderers/wayland/wayland.h index 7d21f5ee..ab498f75 100644 --- a/lib/renderers/wayland/wayland.h +++ b/lib/renderers/wayland/wayland.h @@ -128,6 +128,7 @@ struct window { uint32_t displayed; struct wl_list link; enum bm_align align; + int32_t y_offset; uint32_t align_anchor; bool render_pending; @@ -175,6 +176,7 @@ void bm_wl_window_schedule_render(struct window *window); void bm_wl_window_render(struct window *window, struct wl_display *display, struct bm_menu *menu); void bm_wl_window_set_width(struct window *window, struct wl_display *display, uint32_t margin, float factor); void bm_wl_window_set_align(struct window *window, struct wl_display *display, enum bm_align align); +void bm_wl_window_set_y_offset(struct window *window, struct wl_display *display, int32_t y_offset); void bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab); void bm_wl_window_set_overlap(struct window *window, struct wl_display *display, bool overlap); bool bm_wl_window_create(struct window *window, struct wl_display *display, struct wl_shm *shm, struct wl_output *output, struct zwlr_layer_shell_v1 *layer_shell, struct wl_surface *surface); diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index a3a926ba..f9eb7194 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -354,6 +354,19 @@ bm_wl_window_set_align(struct window *window, struct wl_display *display, enum b wl_display_roundtrip(display); } +void +bm_wl_window_set_y_offset(struct window *window, struct wl_display *display, int32_t y_offset) +{ + if(window->y_offset == y_offset) + return; + + window->y_offset = y_offset; + + zwlr_layer_surface_v1_set_margin(window->layer_surface, window->y_offset, 0, 0, 0); + wl_surface_commit(window->surface); + wl_display_roundtrip(display); +} + void bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab) { diff --git a/lib/renderers/x11/window.c b/lib/renderers/x11/window.c index c0fcd9c5..9884eb38 100644 --- a/lib/renderers/x11/window.c +++ b/lib/renderers/x11/window.c @@ -251,7 +251,6 @@ bm_x11_window_set_y_offset(struct window *window, int32_t y_offset) return; window->y_offset = y_offset; - XMoveWindow(window->display, window->drawable, window->x, window->y + window->y_offset); } void