Wayland support

Add necessary functions for Wayland upwards list mode to work.
This commit is contained in:
Lucas Merritt 2023-10-11 14:04:53 -06:00 committed by Jari Vetoniemi
parent 46c3f76a7d
commit b0751f7ddc
5 changed files with 31 additions and 11 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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)
{

View File

@ -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